akhauriyash/Code-Regression huggingface dataset:
main :: IO ()                                                                                                              
main = do                                                                                                                  
  _:_:x:_ <- map read . words <$> getLine :: IO [Int]                                                                      
  (a,b) <- span (<x) . map read . words <$> getLine                                                                        
  print $ min (length a) (length b)

Measured memory_bytes: 892
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

int dp[3005][3005]; // i: 何番目 j: 前の桁より少ない数が何個あるか
string s;
int N;

int mod = 1e9 + 7;

void add(int& a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}

struct BIT {
    int n;
    vector<int> bit; // 1-indexd

    BIT(int sz) {
        bit.resize(sz + 1);
        n = sz;
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            s %= mod;
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            bit[i] %= mod;
            i += i & -i;
        }
    }
};

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

    cin >> N;
    cin >> s;

    REP(j, N) dp[0][j] = 1;

    FOR(i, 1, N - 1) {
        BIT bit(N + 10);
        REP(j, N - i + 1) bit.add(j + 1, dp[i - 1][j]);

        REP(j, N - i) {
            if (s[i - 1] == '<') {
                dp[i][j] = bit.sum(j + 1);
            } else {
                dp[i][j] = (bit.sum(N) - bit.sum(j + 1) + mod) % mod;
            }
        }
    }

    cout << dp[N - 1][0] << endl;

    return 0;
}


Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", my_dmp(#__VA_ARGS__, __VA_ARGS__)
void my_dmp(const char*) { cerr << endl; }
template <class T, class... U>
void my_dmp(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; my_dmp(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, multiset<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct my_Init { my_Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } my_init;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
////////////////////////////////

int32_t main() {
    int n,m; cin >> n >> m;
    vector<int> a(n),s(n+1); cin >> a;
    rep (i,n) s[i+1] = s[i] + a[i];
    map<int,int> c;
    for (int x : s) c[x%m]++;
    int ans = 0;
    for (auto const& p : c) ans += p.snd*(p.snd-1)/2;
    cout << ans << "\n";
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(ll i = 0; i < n; i++)
#define reprs(i, m, n) for(ll i = n; i >= m; i--)
#define reps(i, m, n) for(ll i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pl;
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}
 
const int MOD = 1000000007;
 
int main(){
 
  ll N,K;
  cin >>N>>K;
 
//  ll dp[K+1][N+1];
  vector<ll> fs;
 
  fs.emplace_back(0);
 
  for(ll i=1;i<=sqrt(N);i++){
    fs.emplace_back(i);
  }
 
  ll size=fs.size()-1;
 
  for(ll i=size;i>=1;i--){
    ll x=N/i;
    if(x==size) continue;
    fs.emplace_back(x);
  }
 
  ll size2=fs.size();
  ll dp[K+1][size2];
  ll temp=0;
 
  reps(i,1,K+1){
    reprs(j,1,size2-1){
      if(i==1){
        dp[i][j]=1;
      }
      else if(j==size2-1){
        dp[i][j]=dp[i-1][1];
      }
      else {
        dp[i][j]=(dp[i][j+1]+dp[i-1][size2-j]*(fs[size2-j]-fs[size2-j-1]))%MOD;
      }
    }
  }
 
  ll ans=0;
 
  reps(j,1,size2){
    ans=(ans+dp[K][j]*(fs[j]-fs[j-1]))%MOD;
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 50296
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; 
int main(void){
    
    ll N, K;
    cin>> N >> K ;
    vector<ll> A(N); 
    ll S=0;
    for(int i=0; i<N; i++){
        cin >> A.at(i) ;
        S+= A.at(i);
    }
    
    ll answer=0;
    
    for(ll d=1; d*d<=S; d++){
        ll D;
        ll P;
        ll M; 
        
        if((S%d)==0){
            D=d; 
            P=0;
            M=0;
            priority_queue<ll> pq; 
            for(int i=0; i<N; i++){
                ll a= A.at(i); 
                a=a%D; 
                pq.push(a);
                P+=a; 
            }
            
            while(P!=M){
                ll a = pq.top();
                pq.pop();
                P-=a;
                M=M+D-a; 
            } 
            
            while(pq.size()>0){
                pq.pop();
            }
            
            if( K>=P ){
                answer = max(D,answer);
            }
            //cout<< d << " "<< P <<" "<<M<< endl;
                
        
            
            
            // D=S/dとして上の繰り返し  
            D=S/d; 
            P=0;
            M=0;
            for(int i=0; i<N; i++){
                ll a= A.at(i); 
                a=a%D; 
                pq.push(a);
                P+=a; 
            }
            
            while(P!=M){
                ll a = pq.top();
                pq.pop();
                P-=a;
                M=M+D-a; 
            } 
            
            while(pq.size()>0){
                pq.pop();
            }
            
            if( K>=P ){
                answer = max(D,answer);
            }
            // 繰り返し終了
            
            
            
            
        }// dがSを割るときのif終了
    }
    cout<< answer << endl; 

}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

using std::cin;
using std::cout;
using std::string;

void my_swap(int& a, int& b)
{
  if (a < b)
  {
    int tmp = a;
    a = b;
    b = tmp;
  }
}

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

  for (;;)
  {
    a = a % b;
    if (a == 0)
    {
      break;
    }
    my_swap(a, b);
  }

  std::vector<int> cd;
  for (int i = b; i > 0; i--)
  {
    if (b % i == 0)
    {
      cd.emplace_back(i);
    }
  }
  std::cout << cd[k-1] << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <stdlib.h>

using namespace std;


long long int calc_casen(int n,int r,int dup)
{
    int i,j,nn;
    long long int* a=
        (long long int*)calloc(n,sizeof(long long int));
    long long int retv;
    nn=(dup)?(n+r-1): n;
    if(nn-r<r) r=nn-r;
    if(r==0) return 1; if(r==1) return nn;
    for(i=1;i<r;i++) a[i]=i+2;
    for(i=3;i<=nn-r+1;i++){
        a[0]=i;
        for(j=1;j<r;j++) a[j]+=a[j-1];
    }
    retv = a[r-1];
    free(a);
    return retv;
}

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

  long long int p,x,y,ans;
  cin >> p;

  x = 0;
  y = 0;
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    if(tmp%2 == 0)
      x++;
    else
      y++;
  }

  if(p==1){

    if(y==0){
      cout << 0 << endl;
      return 0;
    }

    ans = 0;
    long long int tmp = 1;
    while(tmp <= y){
      ans += calc_casen(y,tmp,0);
      tmp += 2;
    }

    for(int i=0;i<x;i++)
      ans *= 2;
  }
  else{
    ans = 0;
    long long int tmp = 0;
    while(tmp <= y){
      ans += calc_casen(y,tmp,0);
      tmp += 2;
    }

    for(int i=0;i<x;i++)
      ans *= 2;

  }
  cout << ans << endl;


  return 0;

}

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

int main(){
	int a[3];
	int K, i_max,max,val,sum;
	cin >> a[0] >> a[1] >> a[2] >> K;
	i_max = 0;
	max = 0;
	sum = a[0];
	for(int i = 1;i < 3; ++i){
		sum += a[i];
		if(a[i] > max){
			i_max = i;
			max = a[i];
		}
	}
	val = max * pow(2,K) + sum-max;
	cout << val << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <algorithm>
using namespace std;

int main()
{
    deque<int> dq;
    int n;
    int N, R;

    scanf("%d", &n);
    dq.resize(n);

    for(int i=0; i<n; i++)
        scanf("%d", &dq[i]);

    sort(dq.begin(), dq.end());

    N = dq[dq.size()-1];

    int f = 0;
    int e = dq.size()-1;
    int cen;

    while(f <= e)
    {
        cen = (f+e)/2;

        if(dq[cen] < N/2)
        {
            f = cen+1;
        }
        else
        {
            e = cen-1;
        }
    }

    if(f == dq.size()-1)
        f--;

    if(f > 0 && abs(dq[f-1]-N/2) < abs(dq[f]-N/2))
        f--;

    printf("%d %d", N, dq[f]);

    return 0;
}


Measured memory_bytes: 640
const fs = require("fs");

function main(input) {
  const tmp = input.split(" ").map(v => parseInt(v));
  const n = tmp[0];
  const r = tmp[1];
  console.log(process(n, r));
}

function process(n, r) {
  if (n > 10)
    return r;
  return r + 100 * (10 - n);
}

main(fs.readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
from itertools import accumulate


N = int(input())
A = [0] + list(accumulate(map(int, input().split())))
min_diff = float("inf")
for i in range(N - 1):
    if abs(A[N] - 2 * A[i + 1]) < min_diff:
        min_diff = abs(A[N] - 2 * A[i + 1])
print(min_diff)


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

int main()
{
    long long N, K;
    cin >> N >> K;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        --A[i];
    }
    vector<bool> seen(N, false);
    seen[0] = true;
    int city_num = 0;
    int dist = 0;
    map<int, int> d;
    d[0] = 0;
    vector<int> mp;
    mp.push_back(0);
    while (1)
    {
        dist++;
        city_num = A[city_num];
        mp.push_back(city_num);
        if (seen[city_num])
        {
            break;
        }
        seen[city_num] = true;
        d[city_num] = dist;
    }
    long long round = dist - d[city_num];
    if (K < dist)
    {
        cout << mp[K] + 1 << endl;
    }
    else if (round == 1)
    {
        if (K >= dist)
        {
            cout << mp[dist] + 1 << endl;
        }
    }
    else
    {
        K -= d[city_num];
        K %= round;
        cout << mp[d[city_num] + K] + 1 << endl;
    }
}


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

using namespace std;

typedef long long int ll;

vector <pair <ll,ll> > veca;
int main()
{
    ll n,a,b,b1,c,c1,i,j,k,p,q,sum;
    sum=1;
    p=0;
    cin >> a >> b;
    if (a==0&&b==100)
        cout << 101 << endl;
    else if (a==0&&b!=100)
        cout << b;
    else if ((a==1)&&(b!=100))
        cout << b*100 << endl;
    else if ((a==1)&&(b==100))
        cout << (b*100)+100 << endl;
    else if ((a==2)&&(b!=100))
        cout << b*10000 << endl;
    else if ((a==2)&&(b==100))
        cout << (b*10000)+10000 << endl;
}




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

int main() {
  char ch;

  do {
    scanf("%c", &ch);

    if (ch >= 'A' && ch <= 'Z')
    {
      ch = ch + 32;
    }
    else if (ch >= 'a' && ch <= 'z')
    {
      ch = ch - 32;
    }    

    printf("%c", ch);
  } while (ch != '\n');

  return 0;
}


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

static const int N = 1000;

int Lcs(string X, string Y) {
    int c[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= m; i++) {c[i][0] = 0;}
    for (int j = 1; j <= n; j++) {c[0][j] = 0;}

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if( X[i] == Y[j] ) {
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }

    return maxl;
}

int main() {
    string s1, s2;
    int n; 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << Lcs(s1, s2) << endl;
    }
    // for (int i = 0; i < n; i++) {
    //     cout << Lcs(s1[i], s2[i]) << endl;
    // }

    return 0;
}


Measured memory_bytes: 7120
#include <bits/stdc++.h>
#define maxi 300005
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ll long long
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define TRACE
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
#define gc getchar
#define REP(i,j,n)               for( i=j;i<n;i++)
#define PER(i,j,n)               for( i=n-1;i>=j;i--)
ll mpow(ll a, ll n,ll mod){
	ll ret=1;ll b=a;
	while(n) {
		if(n&1)
			ret=(ret*b)%mod;
		b=(b*b)%mod;
		n>>=1;
	}
	return (ll)ret;
}
inline void read(int &x){
	x=0;
	register char c=gc();
	for(;c<'0' || c>'9';c=gc());
	for(;c>='0' && c<='9';c=gc())
		x=(x<<3)+(x<<1)+(c-'0');
}
inline void write(int x){
	register char buffor[35];
	register int i=0;
	do{
		buffor[i++]=(x%10)+'0';
		x/=10;
	} while(x);
	i--;
	while(i>=0) putchar(buffor[i--]);
	putchar('\n');
}
inline int in() { int x; read(x); return x; }
void solve();
int dbg=1;
using namespace std;
int main(){
	int t=1;
	//read(t);
	for(int i=0;i<t;i++){
		//printf("Case #%d:\n",i);
		solve();
	}
	return 0;
}
void solve() {
	ll n,i,j,k;
	cin>>n;
	for(i=1;i*i<=n;i++)
		if(n%i==0)
			if(i>=1&&i<=9&&n/i>=1&&n/i<=9){
				cout<<"Yes\n";
				return;
			}
	cout<<"No\n";
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;

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

int f(int x){
    int res = 0;
    while(x%2 == 0){
        x /= 2;
        res++;
    }
    return res;
}

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

    for(int i = 0; i < n; i++){
        if(a[i]%2 == 1){
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    int t = f(a[0]);
    for(int i = 0; i < n; i++){
        if(f(a[i]) != t){ //2で割れる回数が全部一緒の必要
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t; //a[i] /= 2*t
    }
    m >>= t;
    ll l = 1;
    for(int i = 0; i < n; i++){
        l = lcm(l, a[i]);
        if(l > m){
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    int ans = (m+1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
char a[100005];
int len;
int main(){
    scanf("%s",a+1);
    len=strlen(a+1);
    if(a[1]!='A'){
    	cout<<"WA";
    	return 0;
	}
	int tmp=0;
	for(int i=3;i<=len-1;i++){
		if(a[i]=='C')tmp++;
	}
	if(tmp!=1){
		cout<<"WA";
		return 0;
	}
	for(int i=2;i<=len;i++){
		if(a[i]!='C'&&(a[i]<'a'||a[i]>'z')){
			cout<<"WA";
			return 0;
		}
	}
	cout<<"AC";
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    return 0;
}


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

struct suffix_array{

    int n,logn;
    vector<int> rank,sa;

    suffix_array(string s){
        n=s.size();
        logn=floor(log2(n));
        rank.resize(n);
        sa.resize(n);
        rep(i,n){
            rank[i]=s[i];
            sa[i]=i;
        }
        for(int k=0;k<logn;++k){
            auto comp=[&](int a,int b){
                if(rank[a]!=rank[b])return rank[a]<rank[b];
                a=(a+(1<<k)<n)?rank[a+(1<<k)]:-1;
                b=(b+(1<<k)<n)?rank[b+(1<<k)]:-1;
                return a<b;
            };
            sort(sa.begin(),sa.end(),comp);
            vector<int> tmp=rank;
            tmp[sa[0]]=0;
            for(int i=1;i<n;++i)tmp[sa[i]]=tmp[sa[i-1]]+comp(sa[i-1],sa[i]);
            rank=tmp;
        }
    }

    int operator[](int k)const{
        return sa[k];
    }

    int size()const{
        return n;
    }

};

const ll mod = 1e9+7;

struct Matrix{
  static const int maxn = 105;
  ll A[maxn][maxn];
  int n;

  Matrix(int n_): n(n_) {
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        A[i][j] = 0;
  }

  Matrix operator *(const Matrix& o) const {
    Matrix ret(n);
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        for(int k = 0; k < n; ++k){
          ll c = A[i][k] * o.A[k][j] % mod;
          ret.A[i][j] = (ret.A[i][j] + c) % mod;
        }
    return ret;
  }

  static Matrix identity(int n){
    Matrix ret(n);
    for(int i = 0; i < n; ++i)
      ret.A[i][i] = 1;
    return ret;
  }

  Matrix operator ^(long long k) const {
    Matrix ret = identity(n);
    Matrix a = *this;
    while(k){
      if(k & 1)ret = ret * a;
      a = a * a;
      k /= 2;
    }
    return ret;
  }

};

int main(){
    ll n,k;
    cin>>n>>k;
    Matrix M(n);
    rep(i,n){
        rep(j,n){
            cin>>M.A[j][i];
        }
    }
    M=M^k;
    ll ans=0;
    rep(i,n){
        rep(j,n){
            ans+=M.A[j][i];
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    multiset<int> notdone, done;
    for (int i = 0; i < (1 << n); i++) {
        int a;
        cin >> a;
        notdone.insert(-a);
    }
    done.insert(*notdone.begin());
    notdone.erase(notdone.begin());
    for (int i = 0; i < n; i++) {
        multiset<int> temp;
        for (auto x: done) {
            set<int>::iterator it = notdone.upper_bound(x);
            if (it == notdone.end()) continue;
            temp.insert(*it);
            notdone.erase(it);
        }
        for (auto x: temp)
            done.insert(x);
    }
    if (done.size() == (1 << n)) cout << "Yes";
    else cout << "No";
    return 0;
}


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

int g[100][100];
int v, e;

int dfs(int s) {
  int ret;
  for (int t = 0; t < v; t++) {
    if (g[s][t] == 2) return 1;
    if (g[s][t] == 1) {
      g[s][t] = 2;
      ret = dfs(t);
      if (ret) return ret;
      g[s][t] = 0;
    }
  }
  return 0;
}

int main() {
  int s, t, ret;
  cin >> v >> e;
  for (int i = 0; i < e; i++) {
    cin >> s >> t;
    g[s][t] = 1;
  }
  for (s = 0; s < v; s++) {
    ret = dfs(s);
    if (ret) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;

  return 0;
}



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

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

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

void solve(int tc) {
    int n, k;
    cin >> n >> k;
    vt<int> a(n);
    for (int &i : a) cin >> i;

    vt<int> dp(n, 1 << 30);
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k && i - j >= 0; j++) {
            dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));
        }
    }
    cout << dp.back();
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) solve(tc);
}


Measured memory_bytes: 3936
e = input().split()
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

a = int(e[0])
b = int(e[1])
c = int(e[2])
d = int(e[3])

x.append(c)
y.append(d)
xmax = max(x)
ymax = min(y)

if xmax < ymax:
    print("No War")
else:
    print("War")
"""
if xmax < ymax:
    if c < ymax:
        if xmax < d:
            print("No War")
        else:
            print("War")
    else:
        print("War")
else:
    print("War")
"""


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

class Knapsack{
public:
	int* weight;
	int* value;
	int U;
	int N;
	int** memo;
	bool** done;

	Knapsack();
	~Knapsack();

	int full_search(int i, int U);
	int Dynamic_Programming(int i, int U);

};

Knapsack::Knapsack(){
	cin >> N >> U;
	weight = new int[N];
	value = new int[N];
	for (int i = 0; i < N; i++){
		cin >> value[i] >> weight[i];
	}
	memo = new int*[N];
	done = new bool*[N];
	for (int i=0; i < N; i++){
		memo[i] = new int[U+1];
		done[i] = new bool[U+1];
	}
	
}

Knapsack::~Knapsack(){
	delete[] weight;
	delete[] value;
	for (int i=0; i < N; i++){
		delete[] memo[i];
		delete[] done[i];
	}
	delete[] memo;
	delete[] done;
}


int Knapsack::full_search(int i, int U){
	if (i == N)return 0;
	else if (U < weight[i])return full_search(i + 1, U);
	else{
		int res1 = full_search(i + 1, U);
		int res2 = full_search(i + 1, U - weight[i]) + value[i];
		return max(res1, res2);
	}
}

int Knapsack::Dynamic_Programming(int i, int U){
	if (i == N)return 0;
	if (done[i][U])return memo[i][U];
	int res;
	if (U < weight[i])return Dynamic_Programming(i + 1, U);

	int res1 = Dynamic_Programming(i + 1, U);
	int res2 = Dynamic_Programming(i + 1, U - weight[i]) + value[i];
	res = max(res1, res2);

	done[i][U] = true;
	memo[i][U] = res;
	return res;
}



int main(){
	Knapsack *solve = new Knapsack;
	cout << solve->Dynamic_Programming(0, solve->U) << endl;
	delete solve;
}

Measured memory_bytes: 5740
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

for i in range(N):
    r = A[i] - B[i]
    if r < 0:
        ans += min(-r, A[i+1])
        A[i+1] = max(A[i+1]+r, 0)
        ans += A[i]    
    else: ans += B[i]
        
print(ans)


Measured memory_bytes: 18476
#include <iostream>

int main(void){
  int a,b;
  std::cin >> a >> b;

  int coin = 0;
  if(b>a) std::swap(a,b);
  coin += a--;
  if(b>a) std::swap(a,b);
  coin += a--;

  std::cout << coin << std::endl;
  return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
times_a = list(map(int, input().split()))
times_b = list(map(int, input().split()))
read_time = 0
read_time_a = [0]
read_time_b = [0]
for i in range(N):
    read_time_a.append(read_time_a[i]+times_a[i])
for i in range(M):
    read_time_b.append(read_time_b[i]+times_b[i])

ans = 0
for a_count in range(N+1):
    a_read_time = read_time_a[a_count]
    max_b_count = 0
    r = len(read_time_b)
    # 消化時間の配列はソートされている状態だから二分探索
    # 計算量をlog(M)に削減
    while max_b_count + 1 < r:
        c = (max_b_count + r) // 2
        # bがインデックスcで時間がaの時間+bの時間でK以下ならmax_b_countを二分探索の開始位置に更新する。
        if a_read_time + read_time_b[c] <= K:
            max_b_count = c
        # 超えちゃったら二分探索の前方に探索領域の終端を絞る
        else:
            r = c
    # 積読消化時間がKより小さく、a_count + max_b_countの最大数が最大になるものをansに代入し続ける
    if read_time_a[a_count] + read_time_b[max_b_count] <= K:
        ans = max(ans, a_count + max_b_count)
print(ans)


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

#define int            long long int
#define float          long double
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define inf            1e18
#define set_pre(x,y)   fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
using namespace std;
int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
class Graph
{
int n;
list<int>*l;
public:
    void init(int p)
    {
        this->n=p;
        l=new list<int>[p];
    }
    void addEdge(int x,int y)
    {
        l[x].push_back(y);
    }
    map<int,int>m;
    int dfs(int node)
    {
        int ans=0;
        if(m.count(node))
            return m[node];
        for(auto c:l[node])
        {
            ans=max(ans,dfs(c)+1);
        }
        return m[node]=ans;
    }
    void ans()
    {
        vector<int>v(n,0);
        for(int i=0;i<n;i++)
        {
            for(auto c:l[i])
                v[c]++;
        }
        int Ans=0;
        for(int i=0;i<n;i++)
        {
            if(v[i]==0)
                Ans=max(Ans,dfs(i));
        }
        cout<<Ans<<endl;
    }

};
int32_t main()
{
    int n,m;
    cin>>n>>m;
    Graph g;
    g.init(n);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        --x;
        --y;
        g.addEdge(x,y);
    }
    g.ans();
    return 0;
}

Measured memory_bytes: 16640
import collections
s = input()
t = input()

ss = collections.Counter(s)
tt = collections.Counter(t)

slist = []
tlist = []

for i in ss:
    slist.append(ss[i])
for i in tt:
    tlist.append(tt[i])

slist.sort()
tlist.sort()
check = False
if len(slist) == len(tlist):
    check = True
    for i in range(len(slist)):
        if slist[i] != tlist[i]:
            check= False
    

if check:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4016
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){

string s;
cin>> s;
int alphabet[26]={};
char t='a';
rep(i,s.size()){
int l=s[i]-t;
alphabet[l]++;
}
int A=0;
rep(i,26){
    char ans;
    if(alphabet[i]==0){
        ans=t+i;
        cout <<ans <<endl;
        break;
    }
    else{
        A++;
    }
}
    if(A==26){
        cout <<"None"<<endl;
    }

 return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int l, r, x, n, rr, i, j, k, ans, last;
	cin >> n;
	vector<pair<int, int>> v(n);
	for (i = 0; i < n; i++) {
		cin >> x >> rr;
		l = x - rr; 
		r = x + rr;
		v[i] = { r,l };
	}

	ans = n;
	last = -1500000000;
	sort(v.begin(), v.end());
	for (auto p : v) {
		r = p.first;
		l = p.second;

		if (l < last) ans--;
		else last = r;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1656
#include <iostream>

using namespace std;

int main(){
    int a,b;
    
    cin >> a >> b;
    
    if(a < b){
        cout << "a < b";
    }else if(a > b){
        cout << "a > b";
    }else if(a == b){
        cout << "a == b";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3076
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

N, K = map(int, input().split())
snuke = [0] * N
for i in range(K):
    d = int(input())
    A = map(int, input().split())
    for a in A:
        a -= 1
        snuke[a] += 1

cnt = 0
for s in snuke:
    if s == 0:
        cnt += 1

print(cnt)


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

long long n, sum = 0, minn = 1e10, maxn = -1e10;
vector<long long> v;

int main() {
  cin >> n;
  v.resize(n);
  for(int i = 0; i < n; ++i) {
    cin >> v[i];
    sum += v[i];
    minn = min(minn, v[i]);
    maxn = max(maxn, v[i]);
  }
  cout << minn << " " << maxn << " " << sum << endl;

  return 0;
}


Measured memory_bytes: 3184
package main

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

func main() {
	W, H, x, y := ReadInt(), ReadInt(), ReadInt(), ReadInt()
	s := float64(H*W) / 2
	if 2*x == W && 2*y == H {
		fmt.Println(s, 1)
	} else {
		fmt.Println(s, 0)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
#include <iostream>
#include <string>
#include <algorithm>

#define dbg if(0)
using namespace std;
#define ll long long

ll gcd(ll a,ll b){
    ll k=min(a,b);
    ll l=max(a,b);
    ll p=l%k;
    if (p==0)return b;
    return gcd(k,p);
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}


int main(){
    ll n,m;
    ll ans=-1;
    string s,t;
    cin >> n>>m;
    cin >> s>>t;
    bool flag=true;
    for(int nn=0;nn<gcd(n,m);nn++){
        if(s[nn*(n/gcd(n,m))]!=t[nn*(m/gcd(n,m))]){
            flag=false;
            ans=-1;
            break;
        }
        if(!flag){break;}
    }
    if (flag){
        ans=lcm(n,m);
    }
    cout <<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
b = set(a)
c = Counter(a)
for i in range(1, n + 1):
    if not i in b:
        print(0)
    else:
        print(c[i])

Measured memory_bytes: 122892
import java.util.*;
import java.io.*;

class Pair implements Comparable<Pair> {
    final String key;
    final int point;

    public Pair( String key, int point ) {
	this.key = key;
	this.point = point;
    }
    
    public int compareTo ( Pair p ) {
	return -Double.compare( point, p.point );
    }    
}

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	boolean first = true;
	while ( true ) {
	    final int n = stdin.nextInt();
	    if ( n == 0 ) {
		break;
	    }

	    if ( !first ) {
		System.out.println();
	    } else {
		first = false;
	    }

	    ArrayList<Pair> list = new ArrayList<Pair>();
	    for ( int i = 0; i < n; i++ ) {
		final String name = stdin.next();
		final int win = stdin.nextInt();
		final int lose = stdin.nextInt();
		final int draw = stdin.nextInt();
		list.add( new Pair( name, win * 3 + draw ) );
	    }
	    Collections.sort( list );
	    for ( Pair p : list ) {
		System.out.println( p.key + "," + p.point );
	    }
	}	
    }    
}

Measured memory_bytes: 20736
#include<bits/stdc++.h>
using namespace std;
#define N 200005 
#define ll long long 

ll n,a[N],sum;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	priority_queue<ll> q;
	sum=a[n];
	q.push(a[n-1]);
	q.push(a[n-1]);
	for(int i=n-2;i>=1;i--){
		sum+=q.top();q.pop();
		q.push(a[i]);q.push(a[i]);
	}
	
	cout<<sum<<'\n';
}

Measured memory_bytes: 6924
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int n = s.length();
	string t = "";
	rep (i, n){
		if (s[i] == 'C' || s[i] == 'F') t += s[i];
	} // end rep

	bool res = false;
	if (t.length() >= 2){
		for (int i = 0; i < t.length() - 1; ++i){
			if (t[i] == 'C' && t[i+1] == 'F') res |= true;
		} // end for
	} // end if

	cout << (res ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
a = N // 15
b = 60 * (a**2)
c = a * 15
for i in range(c,N+1):
    if i % 3 != 0 and i % 5 != 0:
        b += i
print(b)

Measured memory_bytes: 9048
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		//
		int all_number = 0;
		int answer = 0;
		String out_all = "";

		// テキスト入力クラス
		Scanner sc = new Scanner(System.in);

		//
		while (sc.hasNext()) {
			//
			all_number = sc.nextInt();
			answer = sc.nextInt();

			if (all_number == 0 && answer == 0)
				break;
			int out = 0;
			// 一つ目の数を選ぶ
			for (int f = 1; f <= all_number; f++) {
				// 二つ目の数を選ぶ
				for (int s = 1; s <= all_number; s++) {
					// 同じ数字は使えないので
					if (s != f) {
						// 三つの数を選ぶ
						for (int t = 1; t <= all_number; t++) {
							if (s != f && f != t && t != s && s + f + t == answer) {
								//System.out.println(f+","+s+","+t);
								out = 1 + out;
							}
						}
					}
				}
			}
			// 組み合わせなので、3で割る
			out = out / 6;
			// 出力文字列
			out_all = out_all+""+String.valueOf(out)+"\n";
		}
		// 出力
		System.out.print(out_all);
	}
}

Measured memory_bytes: 20060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, w, max_profit = 0;
	cin >> n >> w;
	vector<pair<ll,ll>> v;
	for(int i = 0;i < n; ++i){
		int wi, vi;
		cin >> wi >> vi;
		max_profit += vi;
		v.push_back(make_pair(wi, vi));
	}
	vector<vector<ll>> ans(2, vector<ll>(max_profit + 1, 1e9 + 7LL));
	int prev = 1;
	ans[prev][0] = 0;
	for(auto&x: v){
		for(int j = 0;j < x.second; ++j)
			ans[!prev][j] = ans[prev][j];
		for(int j = x.second; j <= max_profit; ++j)
			ans[!prev][j] = min(ans[prev][j], ans[prev][j - x.second] + x.first);
		prev ^= 1;
	}
	for(int i = max_profit; i >= 0; --i){
		if(ans[prev][i] <= w){
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 2560
n,k,q = map(int,input().split())
d = {}
for _ in range(q):
    a = int(input())-1
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
for i in range(n):
    if i in d:
        if k-q+d[i] > 0:
            print('Yes')
        else:
            print('No')
    else:
        if k-q > 0:
            print('Yes')
        else:
            print('No')


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> P(N);
    vector<ll> C(N);
    for (auto& p : P) {
        cin >> p;
        --p;
    }
    for (auto& c : C) {
        cin >> c;
    }

    vector<int> isAssigned(N);
    vector<vector<int>> orbits;
    for (int i = 0; i < N; ++i) {
        if (!isAssigned[i]) {
            vector<int> o;
            o.push_back(i);
            int j = i;
            while (P[j] != i)
            {
                o.push_back(P[j]);
                isAssigned[P[j]] = true;
                j = P[j];
            }
            orbits.push_back(o);
        }
    }

    vector<ll> results;
    for (const auto& o : orbits) {
        vector<ll> Co;
        transform(o.cbegin(), o.cend(), back_inserter(Co), [&C](int i){return C[i];});
 
        ll Csum =  accumulate(Co.cbegin(), Co.cend(), (ll)0);
        ll loopNum = Csum > 0 ? max<ll>(K / o.size() - 1, 0) : 0;
        ll Ko = Csum > 0 ? K - loopNum * o.size() : min<ll>(K, o.size());
        
        vector<ll> dp(o.size());
        ll res = *max_element(Co.cbegin(), Co.cend());
        for (auto k = 0; k < Ko; ++k) {
            vector<ll> b;
            transform(Co.cbegin(), Co.cend(), dp.cbegin(), back_inserter(b), [](ll c, ll d){return d + c;});
            copy(b.begin()+1, b.end(), dp.begin());
            dp.back() = b[0];
            res = max(res, *max_element(dp.cbegin(), dp.cend()));
        }
        results.push_back(loopNum * Csum + res);
    }
    ll result =  *max_element(results.cbegin(), results.cend());
    cout << result << endl;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,m,x,min_p=1e9;
    cin>>n>>m>>x;
    int c[n];
    int a[n][m];
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            cin>>a[i][j];
        }
    }
    for(int bit=0;bit<(1<<n);++bit){
        int und[m]={};
        int price=0,flag=1;
        rep(i,n){
            if(bit&(1<<i)){
                price+=c[i];
                rep(j,m){
                    und[j]+=a[i][j];   
                }
            }
        }
        rep(k,m){
            if(und[k]<x)flag=0;
        }
        if(flag==1)min_p=min(min_p,price);
    }
    if(min_p==1e9)cout<<-1<<endl;
    else cout<<min_p<<endl;

    return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int x,n,a,b[109]={0},sum=0,t,t1,q,q1,i;
 cin>>x>>n;
 for(i=1; i<=n; i++)
 {
     cin>>a;
     b[a]=1;
 }
 for(i=sum+x; ;)
 {
     if(b[i]==0)
     {
         t=i-x;
         q=i;
         break;
     }
     i++;
 }
for(i=sum+x-1; ;)
 {
     if(b[i]==0)
     {
         t1=x-i;
         q1=i;
         break;
     }
     i--;
 }
 if(t<t1)
 {
     cout<<q;
 }
 else if(t1<t)
 {
     cout<<q1;
 }
 else if(t1==t)
 {
     cout<<q1;
 }

}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ld long double
const ld pi=3.1415926535897932384626433;


int main()
{
	int h, w;
	bool s[110][110];
	cin >> h >> w;
	rep(i, h) rep(j, w)
	{
		char c;
		cin >> c;
		if(c=='.') s[i][j]=true;
		else s[i][j]=false;
	}
	int dp[110][110];
	dp[0][0]=1;
	if(s[0][0]) dp[0][0]=0;
	for(int i=1; i<h; i++)
	{
		dp[i][0]=dp[i-1][0];
		if(s[i][0]!=s[i-1][0] && !s[i][0]) dp[i][0]++;
	}
	for(int j=1; j<w; j++)
	{
		dp[0][j]=dp[0][j-1];
		if(s[0][j]!=s[0][j-1] && !s[0][j]) dp[0][j]++;
	}
	for(int i=1; i<h; i++)
	{
		for(int j=1; j<w; j++)
		{
			int u, l;
			u=dp[i-1][j];
			if(s[i][j]!=s[i-1][j] && !s[i][j]) u++;
			l=dp[i][j-1];
			if(s[i][j]!=s[i][j-1] && !s[i][j]) l++;
			dp[i][j]=min(u, l);
		}
	}
	cout << dp[h-1][w-1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()


int main(){
  string s;
  cin >> s;
  int a, b;
  rep(i, s.size()) if (s[i] == 'A') {
    a = i;
    break;
  }
  for (int i = s.size() - 1; i >= 0; i--) if (s[i] == 'Z') {
    b = i;
    break;
  }
  cout << b - a + 1 << endl;  
}


Measured memory_bytes: 640
# input here
_INPUT = """\
5 3
1 2
3 4
5 1
"""
"""
K = int(input())
H, W, K = map(int, input().split())
a = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(N)]
p = tuple(map(int,input().split()))
"""
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]



def main():
    n, m = map(int, input().split())
    xy = [list(map(int, input().split())) for i in range(m)]

    uf = UnionFind(n)

    for i in range(len(xy)):
        uf.union(xy[i][0]-1,xy[i][1]-1)
    
    print(-(min(uf.parents)))

    
    
    

            
if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools
    from collections import deque

    # sys.stdin = io.StringIO(_INPUT)
    main()

Measured memory_bytes: 110208
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rp(i,n) for (int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool { return abs(i) < abs(j); });
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;
double pi=3.14159265359;

//出力するよ
void output_tate(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        //if (i != 0)
        //    cout << " ";
        cout << s[i]<<endl;
    }
    //cout << endl;
}

void output_yoko(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        if (i != 0)
            cout << " ";
        cout << s[i];//<<endl;
    }
    cout << endl;
}

int MOD = pow(10, 9) + 7;

int kaijou(int n){
    if(n==0) return 1;
    else{
        return ((n%MOD)*(kaijou(n-1)%MOD))%MOD;
    }
}

bool ispow(int n){
    int rn=sqrt(n);
    if(rn*rn==n) return true;
    else return false;
}

signed main() {
    string s,t; cin>>s>>t;

    map<char,int> s_map,t_map;
    string s_to="",t_to="";

    for(int i=0;i<s.length();i++){
        if(s_map[s[i]]==0){
            s_map[s[i]]=s_map.size()+1;
        }
        s_to+=to_string(s_map[s[i]]);
    }

    for(int i=0;i<t.length();i++){
        if(t_map[t[i]]==0){
            t_map[t[i]]=t_map.size()+1;
        }
        t_to+=to_string(t_map[t[i]]);
    }
    
    //cout<<s_to<<" "<<t_to<<endl;
    if(s_to==t_to) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 4700
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
const ll INF = pow(2,33);

struct SegmentTree{
    vector<ll> node;
    ll cou;
    ll size;
    SegmentTree(int n=1, int first_value = 0){
        cou = 0;
        while( n > (int)pow(2,cou) ) cou++;
        cou++;
        node.resize((int)pow(2,cou),first_value);
        size = (int)pow(2,cou);
    }
    void update(int index, ll value ){
        update_node(convert(index),value);
    }
    void update_node(int node_index, ll value ){
        // 本人と親を更新
        
        // 処理次第
        node[node_index] += value;
        
        if( node_index == 0 ) return;
        
        ll c1,c2;
        c1 = child1(parent(node_index));
        c2 = c1+1;
        // 処理次第。最小値の場合は、左右の子の小さい方を値とする   

        update_node(parent(node_index),value);
    }
    // [a,b)に対して答える

    ll query(int a, int b, int k, int l, int r) {
        // std::cout << l<<" "<<r << std::endl;
        if (r <= a || b <= l){
            return 0;
        }
        if (a <= l && r <= b){
            return node[k]; // ノード k の担当範囲がクエリ区間 [a, b) に完全に含まれる
        }else {
            // 一部だけ範囲が被る場合は左右の子に委託する
            ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
            ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
            return c1+c2; // 左右の子の値の min を取る
        }
    }

    int parent(int node_index){
        return (node_index-1)/2;
    }
    int convert(int origin){
        return origin    +(int)(pow(2,cou-1)-1);
    }
    int rconvert(int node_index){
        return node_index-(int)(pow(2,cou-1)-1);
    }
    int child1( int node_index){
        return node_index*2+1;
    }
};

int main(void){
    ll n,q;
    std::cin >> n>>q;
    SegmentTree seg(n,0);

    for (int i = 0; i < q; i++) {
        int c,x,y;
        std::cin >> c>>x>>y;
        
        if(c==0){
            x--;
            seg.update(x,y);
        }else{
            x--;y--;
            std::cout << seg.query(x,y+1,0,0,seg.size/2) << std::endl;
        }
    }
}



Measured memory_bytes: 5144