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

#if debug
#include "printer.hpp"
#define dump(a) cerr << #a << "(" << __LINE__ << ") = " << a << endl;
#else
#define dump(...)
#endif

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a, b) for (int i = (b)-1; i >= a; i--)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
const ll mod = 1000000007;

ll pow(ll x, ll y) {
  ll ret = 1, tmp = x;
  while (y) {
    if (y % 2) ret = ret * tmp % mod;
    tmp = tmp * tmp % mod;
    y /= 2;
  }
  return ret;
}

ll inverse(ll x) { return pow(x, mod - 2); }

int main() {
  ll A, B, K;
  cin >> A >> B >> K;
  if (K <= A) {
    cout << A - K << ' ' << B << endl;
  } else if (K <= A + B) {
    cout << 0 << ' ' << B - (K - A) << endl;
  } else {
    cout << 0 << ' ' << 0 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
main()
{
	long long k,n,x,i;
	cin>>k>>n;
	vector<long long>v;
	for(i=0;i<n;i++){
		cin>>x;
		v.pb(x);
	}
	sort(v.begin(),v.end());
	set<long long>s;
	for(i=1;i<v.size();i++){
		x=k-abs(v[i]-v[i-1]);
		s.insert(x);
	}
	if(v[0]!=0) x=k-abs(v[i-1]-(k+v[0]));
	else x=k-abs(v[i-1]-k);
	s.insert(x);
	cout<<*s.begin()<<'\n';
}

Measured memory_bytes: 2420
N = int(input())
As = input().split(' ')
As = [int(As[i]) for i in range(N+1)]
Bs = input().split(' ')
Bs = [int(Bs[i]) for i in range(N)]
WIN = 0
for i in range(N):
  if Bs[i] > As[i]:
    WIN += As[i]
    Bs[i] -= As[i]
    As[i] = 0
    if Bs[i] > As[i+1]:
      WIN += As[i+1]
      Bs[i] -= As[i+1]
      As[i+1] = 0
    elif Bs[i] == As[i+1]:
      WIN += As[i+1]
      Bs[i] = 0
      As[i+1] = 0
    else:
      WIN += Bs[i]
      As[i+1] -= Bs[i]
      Bs[i] = 0
  elif Bs[i] == As[i]:
    WIN += As[i]
    Bs[i] = 0
    As[i] = 0
  else:
    WIN += Bs[i]
    As[i] -= Bs[i]
    Bs[i] = 0
print(WIN)

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

const int N = 1e6+10;
const int inf = 1e9;

vector<vector<int>> cum;

bool ok(int x1, int y1, int x2, int y2) {
    if(x1 > x2) swap(x1, x2);
    if(y1 > y2) swap(y1, y2);
    int obs = cum[x2][y2] - (x1>0?cum[x1-1][y2]:0) - (y1>0?cum[x2][y1-1]:0) + (x1>0&&y1>0 ? cum[x1-1][y1-1]:0);
    return obs == 0;
}

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, K;
    cin >> n >> m >> K;
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    sx--, sy--, tx--, ty--;
    vector<string> grid(n);
    for(int i = 0; i < n; i++) cin >> grid[i];
    vector<vector<int>> dis(n, vector<int>(m, inf));
    cum.assign(n, vector<int>(m, 0));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cum[i][j] = (grid[i][j] == '@') + (i>0?cum[i-1][j]:0) + (j>0?cum[i][j-1]:0) - (i>0 && j>0 ? cum[i-1][j-1] : 0);
        }
    }

    vector<set<int>> row(n), col(m);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(i == sx && j == sy) continue;
            if(grid[i][j] == '.') row[i].insert(j), col[j].insert(i);
        }
    }

    queue<int> que;
    que.push(sx);
    que.push(sy);
    dis[sx][sy] = 0;

    while(que.size() > 0) {
        int x = que.front(); que.pop();
        int y = que.front(); que.pop();

        auto it = row[x].lower_bound(y);
        vector<pair<int,int>> visited;
        while(it != row[x].end() && abs((*it)-y) <= K && ok(x,y,x,*it)) {
            visited.push_back({x, *it});
            it++;
        }
        it = row[x].lower_bound(y);
        if(it != row[x].begin()) {
            it--;
            while(abs((*it)-y) <= K && ok(x,y,x,*it)) {
                visited.push_back({x, *it});
                if(it == row[x].begin()) break;
                it--;
            }
        }

        it = col[y].lower_bound(x);
        while(it != col[y].end() && abs((*it)-x) <= K && ok(x,y,*it,y)) {
            visited.push_back({*it, y});
            it++;
        }
        it = col[y].lower_bound(x);
        if(it != col[y].begin()) {
            it--;
            while(abs((*it)-x) <= K && ok(x,y,*it,y)) {
                visited.push_back({*it, y});
                if(it == col[y].begin()) break;
                it--;
            }
        }

        for(auto t : visited) {
            int xx = t.first, yy = t.second;
            row[xx].erase(yy);
            col[yy].erase(xx);
            dis[xx][yy] = dis[x][y] + 1;
            que.push(xx);
            que.push(yy);
        }
    }
//
//    for(int x = 0; x < n; x++) {
//        for(int y = 0; y < m; y++) {
//            cout << dis[x][y] << " ";
//        }
//        cout << endl;
//    }

    int ans = dis[tx][ty];
    if(dis[tx][ty] == inf) ans = -1;
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 152136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    int mx = max({a, b, c});
    int ans = 0;
    if (mx == a) {
        if ((a - b) % 2 != (a - c) % 2) {
            a ++;
            b ++;
            ans ++;
        }
        int x = a - b;
        int y = a - c;
        ans += (x + y) / 2;
    } else if (mx == b) {
        if ((b - a) % 2 != (b - c) % 2) {
            b ++;
            a ++;
            ans ++;
        }
        int x = b - a;
        int y = b - c;
        ans += (x + y) / 2;
    } else {
        if ((c - a) % 2 != (c - b) % 2) {
            c ++;
            a ++;
            ans ++;
        }
        int x = c - a;
        int y = c - b;
        ans += (x + y) / 2;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;cin>>N;
    int A[N];
    bool flag=true;
    int ans=0;
    rep(i,N){
        cin>>A[i];
    }
    while(flag){
        rep(i,N){
            if(A[i]%2==0){
                A[i]/=2;
                continue;
            }else{
                flag=false;
                break;
            }
        }
        if(flag)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
import collections

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


n = int(input())

ls = prime_factorize(n)
c = collections.Counter(ls)

if len(c) == 0:
    print(0)
else:
    ans = 0
    for ci in c.values():
        num = 1
        cnt = 1
        while ci >= num:
            ans += 1
            cnt += 1
            num += cnt
    print(ans)

Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> broken(N,0);
    rep(i,M){
        int x;
        cin >> x;
        broken[x] = 1;
    }
    vector<ll> dp(N + 1);
    dp[0] = 1;
    if(broken[1] == 1){
        dp[1] = 0;
    }
    else{
        dp[1] = 1;
    }
    for(int i = 2; i < N + 1; i++){
        if (broken[i] == 1){
            dp[i] = 0;
        }
        else{
            dp[i] = dp[i - 1] % 1000000007 + dp[i - 2] % 1000000007;
        }
    }
    cout << dp[N] % 1000000007 << endl;
    
}

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

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long Min=0;
    long long sum=0;
    int minp=1;
    for(int i=0;i<n;i++)
    {
        Min+= (a[i]-1)*(a[i]-1);
    }
    for(int p=2;p<=100;p++)
    {
        sum=0;
        for(int i=0;i<n;i++)
        {
            sum+= (a[i]-p)*(a[i]-p);
        }
        if(sum<Min)
        {
            Min=sum;
            minp=p;
        }
    }
    cout<<Min<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a, b = [], []
for i in range(N):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)
c, d = [], []
for j in range(M):
    _c, _d = map(int, input().split())
    c.append(_c)
    d.append(_d)

for i in range(N):
    ans = 10 ** 9
    for j in range(M):
        tmp = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if tmp < ans:
            ans = tmp
            jj = j
    print(jj + 1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
using namespace std;
map <int,int> mp;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;
int N,M;

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

    ll b=1;

    for(int i=0;i<M;i++)b*=2;
    
    ll ans=(100*N+1800*M)*b;

    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
def main():
    a, b, c = map(int, input().split())
    k = int(input())
    cnt = 0
    while(1):
        # print(a)
        # print(b)
        # print(c)
        # print('------------------')
        if cnt-1 == k:
            print('No')
            return
        cnt += 1
        if a < b and b < c:
            print('Yes')
            return
        if not a < b:
            b = 2*b
        elif not b < c:
            c = 2*c
if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
string s[7]={"SUN", "MON", "TUE", "WED","THU", "FRI","SAT"};
string t;
cin>>t;
int ps=0;
for(int i=0;i<7;i++)
{
if(s[i]==t)
{
ps=i;
break;
}
}
cout<<7-ps<<endl;
}

Measured memory_bytes: 3432
#include<iostream>
using namespace std;
int main(){
	int n,i,y,h,a;
	double t,x=1000,w;
	cin >> n >> t >> a;
	for(i=0;i<n;i++){
		cin >> h;
		w=t-0.006*h-a;
		if(w<0)
			w=-w;
		if(w<x){
			x=w;
			y=i;
		}
	}
	cout << y+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, d, x;
	cin >> n >> d >> x;
	int a, ans = x;
	for (int i = 0; i < n; ++i)
	{
		cin >> a;
		ans += d / a + (d % a != 0);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b) {
	while (b > 0) {
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int N, X;
int x[114514];

int asumisu[114514];

int main(void) {
	int i;
	int mikakosi;
	if (scanf("%d%d", &N, &X) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &x[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		asumisu[i] = x[i] - X;
		if (asumisu[i] < 0) asumisu[i] = -asumisu[i];
	}
	mikakosi = asumisu[0];
	for (i = 1; i < N; i++) {
		mikakosi = gcd(mikakosi, asumisu[i]);
	}
	printf("%d\n", mikakosi);
	return 0;
}


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

int main()
{

	int n;
	int a[100];

	cin >> n;
	for( int i = 0; i < n; i++ ) cin >> a[i];
	for( int i = n - 1; i >= 0; i--  ) i != 0 ? cout << a[i] << " " : cout << a[i] << endl;

	return 0;

}

Measured memory_bytes: 1160
<?php

class Scanner
{
  private $arr = [];
  private $count = 0;
  private $pointer = 0;

  public function next()
  {
    if ($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    ++$this->pointer;

    return $result;
  }

  public function hasNext()
  {
    return $this->pointer < $this->count;
  }

  public function nextInt()
  {
    return (int) $this->next();
  }

  public function nextDouble()
  {
    return (float) $this->next();
  }
}

$sc = new Scanner();
$n = $sc->nextInt();
$sum = 0;

for($i=0;$i<$n;$i++){
  $left = $sc->nextInt();
  $right = $sc->nextInt();
  $sum += $right - $left + 1;
}

echo $sum . PHP_EOL;


Measured memory_bytes: 16104
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int X;
int Y;
char A[100][102];
int r[100];
int c[100];
int main(){
  int i, j;
  rd(X);
  rd(Y);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(X);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=0;i<(X);i++){
    for(j=0;j<(Y);j++){
      if(A[i][j]=='#'){
        r[i] = c[j] = 1;
      }
    }
  }
  for(i=0;i<(X);i++){
    if(r[i]){
      for(j=0;j<(Y);j++){
        if(c[j]){
          wt_L(A[i][j]);
        }
      }
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// int X, Y;
// char A[100][102];
// 
// int r[100], c[100];
// {
//   int i, j;
//   rd(X,Y,A(X));
//   rep(i,X) rep(j,Y) if(A[i][j]=='#') r[i] = c[j] = 1;
//   rep(i,X) if(r[i]){
//     rep(j,Y) if(c[j]) wtN(A[i][j]);
//     wtN('\n');
//   }
// }


Measured memory_bytes: 256
k = int(input())
n = 3
cnt = [0] * (k + 1)

for i in range(k, 0, -1):
    cnt[i] = (k // i) ** n
    multiple = i * 2
    while multiple <= k:
        cnt[i] -= cnt[multiple]
        multiple += i

print(sum((i* cnt[i] for i in range(1, k + 1))))


Measured memory_bytes: 9192
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int q = sc.nextInt();
        int cnt = 1;
        char k = 0;
        char l = 0;
        int a2 = 0;
        int b2 = 0;
        List<Character> str = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            str.add(s.charAt(i));
        }
        while (cnt <= q) {
            String order = sc.next();
            int a = sc.nextInt();
            int b = sc.nextInt();
            a2 = a;
            b2 = b;
            if (order.equals("print")) {
                for (int i = 0; i <= b - a; i++) {
                    System.out.print(str.get(i + a));
                }
                System.out.println("");
            } else if (order.equals("reverse")) {

                for (int i = 0; i < (b - a) / 2 + ((b - a) % 2); i++) {
                    k = str.get(a2);
                    l = str.get(b2);
                    str.set(a2, l);
                    str.set(b2, k);
                    a2++;
                    b2--;
                }
            } else {
                String p = sc.next();
                for (int i = 0; i <= b - a; i++) {
                    str.set(a2, p.charAt(i));
                    a2++;
                }
            }
            cnt++;
        }
    }
}

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

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if(a - b >= 0){
        cout << "delicious" << endl;
    }else if((a + x) - b >= 0){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;

const ll mod = 1e9 + 7;
int n;
char S[200005];
int C[200005];
void input() {
    cin >> n >> S + 1;
}

void calc() {
    int cnt[2] = {};
    int sum = 0;
    for (int i = 1; i <= 2 * n; i++) {
        int c = i & 1;
        c ^= (S[i] == 'W');
        C[i] = c;
        if (c == 1) sum++;
        else sum--;
        if (sum < 0) return;
    }
    if (sum != 0) return;
    sum = 0;
    ll ans = 1;
    for (int i = 1; i <= n; i++) ans = ans * i % mod;
    for (int i = 1; i <= 2 * n; i++) {
        if (C[i] == 1) sum++;
        else {
            ans = ans * sum % mod;
            sum--;
        }
    }
    cout << ans;
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    input();
    calc();
    cout << 0;
    return 0;
}

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

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    a, b, c = read_h()

    mod = set((a * i) % b for i in range(1, b + 1))
    if c in mod:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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

const int MAX_N=1001001;
int par[MAX_N], depth[MAX_N];

void init(int n){
    for(int i=0; i<n; i++){
        par[i]=i;
        depth[i]=0;
    }
}

int find(int x){
    if(par[x] == x) return x;
    return par[x]=find(par[x]);
}

void unite(int x, int y){
    x=find(x), y=find(y);
    if(x == y) return;
    if(depth[x] < depth[y]) par[x]=y;
    else{
        par[y]=x;
        if(depth[x] == depth[y]) depth[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

int main(){
    int N, M; cin >> N >> M;
    vi p(N);
    for(auto &x : p){
        cin >> x;
        x--;
    }
    vi x(M), y(M);
    init(N);
    for(int i=0; i<M; i++){
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
        unite(x[i], y[i]);
    }

    int ans=0;
    for(int i=0; i<N; i++){
        if(same(i, p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5088
#include <bits/stdc++.h>
 
using namespace std;
 
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forp(a,b,c) for(int (a)=(b); (a)<(c); (a++))
#define form(a,b,c) for(int (a)=(b); (a)>(c); (a--))
#define fori(a,b) for(auto (a):(b))
#define pb(a) push_back(a)
#define INF ((unsigned) ~0)
#define endl "\n"
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}
 
int main()
{
    fastIO
    int n=0, ac=0, wa=0, tle=0, re=0;
    string s;
    cin>>n;
    while(n--)
    {
        cin>>s;
        if(s=="AC") ac++;
        else if(s=="WA") wa++;
        else if(s=="TLE") tle++;
        else if(s=="RE") re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


/* 4 方向への隣接頂点への移動を表すベクトル */
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

vector<string> field;

vector<vector<int>> bfs(int sx, int sy, int height, int width){
    // 各セルの最短距離 (訪れていないところは -1 としておく)
    vector<vector<int> > dist(height, vector<int>(width, -1));     
    dist[sx][sy] = 0; // スタートを 0 に

    // 探索中に各マスはどのマスから来たのかを表す配列 (最短経路長を知るだけなら、これは不要)
    vector<vector<int> > prev_x(height, vector<int>(width, -1));
    vector<vector<int> > prev_y(height, vector<int>(width, -1));

    // 「一度見た頂点」のうち「まだ訪れていない頂点」を表すキュー
    queue<pair<int, int> > que; 
    que.push(make_pair(sx, sy)); // スタートを push


    ////////////////////////////////////////
    /* 幅優先探索を実施 */
    ////////////////////////////////////////    

    /* キューが空になるまで */
    while (!que.empty()) {
        pair<int, int> current_pos = que.front(); // キューの先頭を見る (C++ ではこれをしても pop しない)
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop(); // キューから pop を忘れずに

        // 隣接頂点を探索
        for (int direction = 0; direction < 4; ++direction) {
            int next_x = x + dx[direction];
            int next_y = y + dy[direction];
            if (next_x < 0 || next_x >= height || next_y < 0 || next_y >= width) continue; // 場外アウトならダメ
            if (field[next_x][next_y] == '#') continue; // 壁はダメ

            // まだ見ていない頂点なら push
            if (dist[next_x][next_y] == -1) {
                que.push(make_pair(next_x, next_y));
                dist[next_x][next_y] = dist[x][y] + 1; // (next_x, next_y) の距離も更新
                prev_x[next_x][next_y] = x;  // どの頂点から情報が伝播して来たか、縦方向の座標をメモ
                prev_y[next_x][next_y] = y;  // どの頂点から情報が伝播して来たか、横方向の座標をメモ
            }
        }
    }
    return dist;
}

int main() {

    ////////////////////////////////////////
    /* 入力受け取り */
    ////////////////////////////////////////

    /* 縦と横の長さ */
    int H, W;
    cin >> H >> W;

    /* 盤面 */
    field.resize(H);
    for (int h = 0; h < H; ++h) cin >> field[h];

    int ans = 0;
    rep(i,H){
        rep(j,W){
            int tmp = 0;
            if (field[i][j] == '#') continue;
            // 探索開始
            vector<vector<int> > Alldist(H, vector<int>(W));            
            Alldist = bfs(i, j, H, W);
            rep(k,H){
                rep(l,W){
                    ans = max(ans , Alldist[k][l]);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

int main(){
    bool b1 = true;
    int N, M, A;
    A = 0;
    cin >> N >> M;

    vector<int> vec(M);
    for (int i = 0; i < M; i++){
        cin >> vec.at(i);
    }

    for (int i = 0; i < M; i++){
        A = A + vec.at(i);
    }

    if (A > N)
        b1 = false;
    
    if (b1){
        cout << N - A << endl;
    }else{
        cout << -1 << endl;
    }
            
}



Measured memory_bytes: 3664
package main

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

var (
	N, M int
	s    [5]int
	c    [5]string
)

func main() {
	readVariables()
	answer := -1
Outer:
	for i := 0; i < ModPow(10, N, 0); i++ {
		digits := strconv.Itoa(i)
		if len(digits) != N {
			continue
		}
		for j := 0; j < M; j++ {
			digit := string(digits[s[j]-1])
			if digit != c[j] {
				continue Outer
			}
		}
		if answer == -1 {
			answer = i
		}
		answer = MinInt(answer, i)
	}
	fmt.Println(answer)
}

func readVariables() {
	N, M = nextInt(), nextInt()
	for i := 0; i < M; i++ {
		s[i], c[i] = nextInt(), nextStr()
	}
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int m, f, r, goukei, i;
	char rank[5] = {'A','B','C','D','F'};
	while (1)
	{
		scanf("%d %d %d", &m, &f, &r);
		goukei = m + f;
		if (m == -1 && f == -1 && r == -1)
			break;
		if ((m == -1 || f == -1) || goukei < 30)
		{
			i = 4;
		}else
		if (goukei >= 80)
			i = 0;
			else
		if (65 <= goukei)
			i = 1;
			else
		if (50 <= goukei)
			i = 2;
			else
		if (30 <= goukei)
		{
			i = 3;
			if (r >= 50)
				i = 2;
		}
		printf("%c\n", rank[i]);
	}
	return 0;
}

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

int main()
{
  int f[2];
  int i,j;
  string r,a;
  while(cin>>r>>a,r!="0"&&a!="0"){
    f[0]=f[1]=0;
    for(i=0;i<4;i++)
      for(j=0;j<4;j++)
	if(a[i]==r[j]) f[i!=j]++;
    cout<<f[0]<<" "<<f[1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 912
s = input()
n = len(s)
ans1 = 0
ans2 = 0
for i in range(n):
    if s[i] == '0' and i % 2 == 0:
        ans1 += 1
    elif s[i] == '1' and i % 2 == 1:
        ans1 += 1
for i in range(n):
    if s[i] == '1' and i % 2 == 0:
        ans2 += 1
    elif s[i] == '0' and i % 2 == 1:
        ans2 += 1
if ans1 < ans2:
    ans2 = ans1
print(ans2)


Measured memory_bytes: 3316
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int n; cin >> n;
    vector<ll> da(n);
    rip(i,n,0) cin >> da[i];
    ll k = 0;
    rip(i,n,2) k^=da[i];
    if((da[0]+da[1]-k)&1) {
        cout << -1 << endl;
        return 0;
    }
    ll m = (da[0]+da[1]-k)>>1, now = 1LL << 41;
    if(((da[0]+da[1]-k)&1) == 1 || (m&k) > 0) {
        cout << -1 << endl;
        return 0;
    }
    while(now) {
        if((m|now) <= da[0] && (k&now) > 0) m |= now;
        now >>= 1;
    }
    if(m>da[0] || m == 0) {
        cout << -1 << endl;
        return 0;
    }
    else {
        cout << da[0]-m << '\n';
    }
}

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

int n;
int main() {
  cin >> n;
  vector <long long> v(n);
  for(int i = 0; i < n; i++) {
    cin >> v[i];
  }   
  long long sum = accumulate(v.begin(), v.end(), 0LL);
  for(int i = 1; i < n; i++) {
    v[i] += v[i - 1];
  }
  long long ans = LONG_MAX;
  for(int i = 0; i < n - 1; i++) {
    long long x = v[i];
    long long y = sum - v[i];
    ans = min(ans, abs(x - y));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, NIL;
int maxh;

void insert(int k){
  int H;
  Node y=NIL;
  Node x=root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent = y;
  if(y==NIL){
    root = z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n);
  maxh=0;
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(strcmp(com,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(com,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25156
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
	int x, y, z, a = 0;
	scanf("%d %d %d", &x, &y, &z);
	if (x == y && y == z) {
		a = 1;
	}
	else {
		for (int i = 1; i <= z; i++) {
			if (z % i == 0 && x <= i && i <= y)
				a++;
		}
	}printf("%d\n", a);
	return 0;
}


Measured memory_bytes: 2108
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    a=list(map(int,sys.stdin.readline().split(' ')))
    s=sum(a)

    ans=0
    for i in range(n):
        s-=a[i]
        val=(s*a[i])%mod
        ans+=val
        ans%=mod
    print(ans%mod)
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 31072
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>
#include <set>
#include <string>

using namespace std;

long long int n;

char decode (int x) {
    return 'a'+(x);
}

int main() {
    cin>>n;

    string res = "";
    int len = 0;
    long long int  cur = 0;
    long long int prod = 1;

    long long int N = n;
    while(true){
        len++;
        prod*=26;
        cur+=prod;
        if(cur>=n) break;
    }

    cur-=prod;
    N-=cur;
    N--;

    for(int i=0;i<len;i++) {
        res+=decode(N%26);
        N/=26;
    }

    reverse(res.begin(), res.end());
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main()
{
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	if(a-b>=0) printf("delicious\n");
	else if ((a+x-b)>=0) printf("safe\n");
	else printf("dangerous\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;

int main(){
	int n;
	cin>>n;
	int arr[n];
	for(int i=0; i<n; i++) cin>>arr[i];
	int m;
	cin>>m;
	for(int c=0; c<m; c++){
		int idx, x;
		cin>>idx>>x;
		--idx;
		int sum = 0;
		for(int i=0; i<n; i++){
			if(i==idx) sum += x;
			else sum += arr[i];
		}
		cout<<sum<<endl;
	}
}


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

using namespace std;
using ll = long long;
const int mod = 1e9 + 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 { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

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

struct UnionFind {
    vector<int> d;

    UnionFind(int n = 0) : d(n, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return -d[find(x)]; }
};

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll dfs(int n, ll x, ll p, ll b, vector<pair<ll, ll>> &A) {
    if (n < 0)return p;
    ll pp = A[n - 1].first, bb = A[n - 1].second;
    cout << n << " " << p << " " << b << " " << pp + bb + 2 << endl;
    ll res;
    if (x < p + b + pp + bb + 2)res = dfs(n - 1, x, p, b, A);
    else res = dfs(n - 1, x, p + pp + 1, b + bb + 1, A);
    return res;
}


int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = 0;
    ans += b / x - a / x;
    if (a % x == 0)ans++;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<map>

using namespace std;

map<int, bool> cnt;

int main(void)
{
    cin.sync_with_stdio(false); cin.tie(NULL);
    int N;  cin >> N;

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

    int res = 0;
    for (auto it : cnt)
        if (it.second)
            res++;

    cout << res << endl;

}


Measured memory_bytes: 4992
/* SPARROW 2019 */
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long

#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x)
#define ps printf(" ")
#define pn printf("\n")
#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)
#define in(x,y) insert({x,y})
#define sv(a) sort(a.begin(),a.end())
#define zero(arr,a) memset(arr,a,sizeof arr)
#define mk
#define mx

int fx[]={0,1,1,1,0,-1,-1,-1};
int fy[]={1,1,0,-1,-1,-1,0,1};

int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);
    //freopen("1015.txt","w",stdout);

    ll a;
    cin>>a;

    ll ans=a*a;
    ans*=(ll)3;

    cout<<ans;pn;
    return 0;
}



Measured memory_bytes: 256
import time
def main():
    N = int(input())
    a = [list(map(int, input().split())) for i in range(N)]
    start = time.time()
    now = [0] * N
    day = 0
    gamed_day = [-1] * N
    finished = 0
    while True:
        if time.time() - start > 1.6:
            print((N*(N-1))//2)
            break
        had_game = False
        all_finish = True
        for i in range(N-1, -1, -1):
            if now[i] < N-1 and gamed_day[i] != day:
                all_finish = False
                want = a[i][now[i]] - 1
                if gamed_day[want] != day:# 今日試合していない
                    if a[want][now[want]] - 1 == i:# 相手の試合相手が自分
                        now[want] += 1
                        now[i] += 1
                        if now[want] >= N-1:
                            finished += 1
                        if now[i] >= N-1:
                            finished += 1
                        gamed_day[i] = day
                        gamed_day[want] = day
                        had_game = True
                        # print(day+1, i+1, want+1)
        if all_finish or finished == N:
            if had_game:
                print(day+1)
            else:
                print(day)
            break
        if not had_game:
            print(-1)
            break
        day += 1
    # print(now)

if __name__ == "__main__":
    main()


Measured memory_bytes: 35064
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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


int main() {
	ll X, N;
	cin >> X >> N;

	vector<ll> p(N + 1);
	repn(i, N) cin >> p[i];

	vector<ll> a(102, 1);
	repn(i, N) a[p[i]] = 0;

	ll ans = 0;
	rep(i, 102) {
		if (a[i] == 1) { 
			if (abs(X - ans) > abs(X - i)) { ans = i; }
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <math.h>
#include <bitset>
#include <vector>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

typedef long long ll;

const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_MAX = 1e9;

int n, mx, m;

int d[100000], u[100000];

vector <int> g[100000];

int dfs (int x)
{
	if (u[x]) return d[x];

	u[x] = 1;

	for (int i = 0; i < g[x].size (); i++)
	{
		int to = g[x][i];

		d[x] = max (d[x], dfs (to) + 1);
	}

	mx = max (mx, d[x]);

	return d[x];
}

int main () 
{
	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		int u, v;

		scanf ("%d%d", &u, &v);

		g[u-1].push_back (v - 1);
	}

	for (int i = 0; i < n; i++)
		if (!u[i]) dfs (i);

	cout << mx;
}

Measured memory_bytes: 8576
#include<stdio.h>
#include<string.h>

#define M 1524287
#define L 14

char H[M][L];

int getChar(char ch);
long long getKey(char str[]);
int h1(int key);
int h2(int key);
int find(char str[]);
int insert(char str[]);


int main(){
	
	int i, n;
	char str[L], com[9];
	
	for ( i = 0; i < M; i++ ){
		H[i][0] = '\0';
	}
    
	scanf("%d", &n);
    
	for ( i = 0; i < n; i++ ){
		scanf("%s %s", com, str);
	
		if ( com[0] == 'i' ){
		    insert(str);
		}else{
		    if (find(str)){
				printf("yes\n");
		    }else {
				printf("no\n");
		    }
		}
	}
	
	return 0;
}


int getChar(char ch){

	if( ch == 'A') return 1;
	else if( ch == 'C') return 2;
	else if( ch == 'G') return 3;
	else if( ch == 'T') return 4;
	else return 0;
	
}

long long getKey(char str[]){
	
	long long sum = 0, p = 1, i;
	
	for ( i = 0; i < strlen(str); i++ ){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	
	return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + ( key % ( M - 1 ) );  }

int find(char str[]){

	long long key , i = 0, j;
	
	key = getKey(str);
	
	while(1){

		j = ( h1(key) + i * h2(key) ) % M;
		
		if( strcmp( str,H[j] ) == 0 ){
			return 1;
		}else if( strlen(H[j])==0 ){
			return 0;
		}
		
		i++;
		
	}
	
	return 0;

}

int insert(char str[]){

	long long key , i = 0 , j;
	
	key = getKey(str);
	
	while(1){
		
		j = ( h1(key) + i * h2(key) ) % M;
		
		if( strcmp( str,H[j] ) == 0  ){
			return 1;
		}else if( strlen(H[j]) == 0 ){
			strcpy( H[j],str );
			return 0;
		}
		
		i++;
		
	}
	
	return 0;

}




Measured memory_bytes: 22564
#include<bits/stdc++.h>
using namespace std;
#define int long long
template <class Q>
void clearQueue(Q & q) {
    q = Q();
}
char arr[1001][1001];
void solve(){
    int h,w;cin>>h>>w;
    int a,b,dx,dy;cin>>a>>b>>dx>>dy;
    a--;b--;dx--;dy--;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>arr[i][j];
        }
    }
    bool ok=false;
    deque<pair<int,int> > dq;
	int dist[h][w];
	for(int i = 0; i < h;++i){
		for(int j = 0; j < w;++j){
			dist[i][j] = 1e7;
		}
	}
	dist[a][b] = 0;
	dq.push_back({a,b});
	while(!dq.empty()){
		pair<int,int> cur_node = dq.front();
		dq.pop_front();
		int row = cur_node.first;
		int col = cur_node.second;
		if(row == dx && col == dy){
			ok = true;
			break;
		}
		for(int dx = -2;dx <= 2;++dx){
			for(int dy = -2;dy <= 2;++dy){
				int nrow = row + dx;
				int ncol = col + dy;
				if(nrow == row && ncol == col)
					continue;
				if(nrow < 0 || ncol < 0 || nrow >= h || ncol >= w)
					continue;
				int w = 1;
				if(arr[nrow][ncol] == '#')
					continue;
				if((abs(nrow-row) == 1 && abs(ncol-col) == 0) || (abs(ncol-col) == 1 && abs(nrow-row) == 0))
					w = 0;
				if(dist[nrow][ncol] > dist[row][col] + w){
					dist[nrow][ncol] = dist[row][col] + w;
					if(w == 0)
						dq.push_front({nrow,ncol});
					else
						dq.push_back({nrow,ncol});
				}
			}
		}
	}
    if(!ok) dist[dx][dy]=-1;
    cout<<dist[dx][dy];
} 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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


ll gcd(ll a,ll b) {
  if(b==0) {
return a;
  }
  a%=b;
 ll s= gcd(b,a);
  return s;
}
  

 
int main() {
ll K;
  cin>>K;
  ll ans=0;
  for(ll i=1;i<=K;i++) {
for(ll j=1;j<=K;j++) {
  for(ll h=1;h<=K;h++) {
ans+=gcd(gcd(i,j),h);
  }
}
    
  }

  
  
  cout<<ans<<endl;
}


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

int main() {
    int N,i,j,k,r=0;
    cin >> N;
    vector<int> L(N);

    for(i=0; i<N; i++)
        cin >> L.at(i);
  	sort(L.begin(), L.end());

    for(i=0; i<N; i++)
      for(j=i+1; j<N; j++)
        for(k=j+1; k<N; k++)
          if(L.at(k) < L.at(i)+L.at(j))
            r++;
    
    cout << r << endl;
}

Measured memory_bytes: 256
// 200220.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    int p[20];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    int first = 0;
    int second = 0;
    int third = 0;
    int large_number = 0;
    int count = 0;
    for (int i = 1; i < n - 1; i++) {
        large_number = 0;
        first = p[i - 1];
        second = p[i];
        third = p[i + 1];
        if (second < first) {
            large_number++;
        }
        if (second < third) {
            large_number++;
        }
        if (large_number == 1) {
            count++;
        }
    }
    cout << count << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256