akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
a = gets.split.map(&:to_i).sort!.reverse!
point = a.shift
idx = 0
loop do
  n = [a[idx * 2 + 1], a[idx * 2 + 2]].count(nil)
  break if n == 2

  point += a[idx] * (2 - n)
  idx += 1
end
puts point

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int dpl[55][110];
int dpr[55][110];
int N, K;
int V[55];

signed main() {
    cin >> N >> K;
    rep(i, N) {
        cin >> V[i];
    }
    priority_queue<int, vector<int>, greater<int>> que1, que2;
    rep(i, N) {
        dpl[i + 1][i + 1] = dpl[i][i] + V[i];
        if (V[i] < 0) {
            que1.push(V[i]);
            que2 = que1;
            int k = 1;
            while (!que2.empty()) {
                dpl[i + 1][i + 1 + k] = dpl[i + 1][i + 1 + k - 1] - que2.top();
                que2.pop();
                k++;
            }
            while (i + 1 + k < 110) {
                dpl[i + 1][i + 1 + k] = dpl[i + 1][i + 1 + k - 1];
                k++;
            }
        } else {
            rep(k, que1.size()) {
                dpl[i + 1][i + 1 + k + 1] = dpl[i][i + k + 1] + V[i];
            }
            int k = que1.size();
            while (i + 1 + k < 110) {
                dpl[i + 1][i + 1 + k + 1] = dpl[i + 1][i + 1 + k];
                k++;
            }
        }
    }
    reverse(V, V + N);
    while (!que1.empty())que1.pop();
    rep(i, N) {
        dpr[i + 1][i + 1] = dpr[i][i] + V[i];
        if (V[i] < 0) {
            que1.push(V[i]);
            que2 = que1;
            int k = 1;
            while (!que2.empty()) {
                dpr[i + 1][i + 1 + k] = dpr[i + 1][i + 1 + k - 1] - que2.top();
                que2.pop();
                k++;
            }
            while (i + 1 + k < 110) {
                dpr[i + 1][i + 1 + k] = dpr[i + 1][i + 1 + k - 1];
                k++;
            }
        } else {
            rep(k, que1.size()) {
                dpr[i + 1][i + 1 + k + 1] = dpr[i][i + k + 1] + V[i];
            }
            int k = que1.size();
            while (i + 1 + k < 110) {
                dpr[i + 1][i + 1 + k + 1] = dpr[i + 1][i + 1 + k];
                k++;
            }
        }
    }
    int ans = 0;
    for (int a = 0; a <= N; ++a) {
        for (int b = 0; b <= N - a; ++b) {
            for (int k = a; k <= K; ++k) {
                if (K - k < b)break;
                int bk = K - k;
                ans = max(ans, dpl[a][k] + dpr[b][bk]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	int n;
	ll k;
	cin >> n >> k;
	vector<int> a;
	int temp = 0;
	for(int i=0; i<n; i++){
			cin >> temp;
			temp--;
			a.emplace_back(temp);
	}
	vi town(n,-1);
	town[0] = 0;
	int next = a[0];
	int dist = 1;
	while(town[next] == -1){
		town[next] = dist;
		dist++;
		next = a[next];
	}
	int loop = dist - town[next];
	int ans = 0;
	if(k > town[next]){
		k -= town[next];
		k = k % loop;
		ans = next;
	}
	rep(i,k){
		ans = a[ans];
	}
	ans++;
	cout << ans << endl;

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 6376
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    int K; cin>>K;

    int cnt=0;
    char c;
    REP(i,SZ(s)){
        if(s[i]=='1') cnt++;
        else{
            c=s[i]; break;
        }
    }
    if(K<=cnt) cout<<1<<endl;
    else cout<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 
 typedef long long int ll;
 ll MOD = 1000000007;
 
 // ====================================================================
 
 int main() {
   string s;
   cin >> s;
   vector<vector<ll>> dp(s.size(), vector<ll>(13, 0));
 
   // 1行目を初期化する
   if (s[0] == '?')
     for (int i = 0; i < 10; i++) dp[0][i] = 1;
   else
     dp[0][s[0] - '0'] = 1;
 
   // 配るDPをしていく
   for (int k = 0; k < s.size() - 1; k++) {
     if (s[k + 1] == '?') {  // 次の文字が自由に決められる
       for (int i = 0; i < 13; i++) {
         for (int j = 0; j < 10; j++) { // 全ての文字を試す
           dp[k + 1][(i * 10 % 13 + j) % 13] += dp[k][i];
           dp[k + 1][(i * 10 % 13 + j) % 13] %= MOD;
         }
       }
     } else {  // 次の文字が指定されている
       for (int i = 0; i < 13; i++) {
         dp[k + 1][(i * 10 % 13 + (s[k + 1] - '0')) % 13] += dp[k][i];
         dp[k + 1][(i * 10 % 13 + (s[k + 1] - '0')) % 13] %= MOD;
       }
     }
   }
 
   cout << dp[s.size() - 1][5] << endl;
 }

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+1;
int a[maxn];
int main()
{
	int n,k,minh=1e9;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=k-1;i<n;i++)	 
	{
		minh=min(minh,abs(a[i]-a[i-k+1]));
	}
	cout<<minh<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
typedef long long ll ;
typedef pair<int , int> PII ;
const int N = 1e5 + 10 , INF = 0x3f3f3f3f , mod = 2019 ;
unordered_map<int , int> mp ;
int main()
{
  string s ;
  cin >> s ;
  s = " " + s ;
  int n = s.size() - 1 ;
  int now = 0 , ans = 0 ;
  mp[0] = 1 ;
  int x = 1 ;
  for(int i = n; i >= 1 ;i --)
   {
     int c = now ;
     now = now + x * (s[i] - '0');
     x *= 10 ;
     x %= mod ;
     now %= 2019 ;
  //   cout << now << " " ;
     ans += mp[now] ;
     mp[now] ++ ;
   }
   cout << ans << endl ;
  return 0 ;
}


Measured memory_bytes: 3924
#include<stdio.h>
#include <stdlib.h>
int main(void){
	int N;
	int *S;
	int i,j,c=100;
	int total=0;
	
	scanf("%d",&N);

	S = (int *)malloc(N*sizeof(int));

	
	for(i=0;i<N;i++){
		scanf("%d",&S[i]);
	}

	for(i=0;i<N;i++){
		total+=S[i];
	}
	if(total%10==0){
		for(i=0;i<N;i++){
			if(c>S[i]&&S[i]%10!=0)	c=S[i];
		}
	total=total-c;
	}
	if(total%10==0) printf("0");
	else printf("%d",total);
	free(S);
}

Measured memory_bytes: 128
import java.io.*;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out = new PrintWriter(System.out);
static boolean[] hasParent;

static class Node{
    int id;
    int p;
    int rank;
    int k;
    int[] c;
    String type;
    Node(int id){
	this.id=id; this.p=-1; this.rank=-1; this.type="internal node";
    }
}
    
    public static void main(String[] args) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	int num=Integer.parseInt(br.readLine());
	Node[] ns=new Node[num];
	hasParent=new boolean[num];
	StringTokenizer st;
	StringBuilder sb;
	for(int i=0;i<num;i++){
	    ns[i]=new Node(i);
	}
	for(int i=0;i<num;i++){
	    st=new StringTokenizer(br.readLine());
	    int id=Integer.parseInt(st.nextToken());
	    Node n=ns[id];
	    int k=Integer.parseInt(st.nextToken());
	    n.k=k;
	    if(k==0) n.type="leaf";
	    else{
		n.c=new int[k];
		for(int j=0;j<k;j++){
		    int c=Integer.parseInt(st.nextToken());
		    n.c[j]=c;
		    ns[c].p=id;
		    hasParent[c]=true;
		}
	    }
	}
	for(int i=0;i<num;i++){
	    if(ns[i].rank<0) ns[i].rank=setRank(i,ns);
	}
	for(int i=0;i<num;i++){
	    Node an=ns[i];
	    sb=new StringBuilder();
	    sb.append("node ");
	    sb.append(i);
	    sb.append(": parent = ");
	    sb.append(an.p);
	    sb.append(", depth = ");
	    sb.append(an.rank);
	    sb.append(", ");
	    sb.append(an.type);
	    sb.append(", [");
	    if(an.k!=0){
		for(int j=0;j<an.k;j++) sb.append((j==an.k-1)?an.c[j]:an.c[j]+", ");
	    }
	    sb.append("]");
	    sb.append(System.getProperty("line.separator"));
	    out.print(sb);
	}
	out.flush();
    }
    
    private static int setRank(int now,Node[] ns){
	if(ns[now].rank>=0) return ns[now].rank;
	if(!hasParent[now]){
	    ns[now].type="root";
	    return ns[now].rank=0;
	}
	return ns[now].rank=setRank(ns[now].p,ns)+1;
    }
}



Measured memory_bytes: 80840
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
a = [None] + a

ans = [[None] * w for _ in range(h)]

cur = 1
way = 1
r, c = 0, 0
flg = True
while cur <= n:
    ans[r][c] = cur
    a[cur] -= 1
    if a[cur] == 0:
        cur += 1

    if (w == 1) or ((c == 0 or c == w - 1) and (not flg)):
        r += 1
        way *= -1
        flg = True
    else:
        c += way
        flg = False
    # print(r, c)

for aa in ans:
    print(*aa)


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

int H,W;

while(1){
scanf("%d %d",&H,&W);

if(H==0&&W==0) break;

for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){
      printf("#");
}
    printf("\n");
}
  printf("\n");
}
return 0;
}




Measured memory_bytes: 2100
cube = input()

zero_count = 0
one_count = 0

for i in range(len(cube)):
    if cube[i] == '0':
        zero_count += 1
    else:
        one_count += 1

if zero_count < one_count:
    print(zero_count * 2)
else:
    print(one_count * 2)


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

const int mod = 1000000007;
int N;
vector<int> arr;
vector<int> po;

int main() {
    po.resize(100010);
    po[0] = 1;
    for(int i = 1; i < 100010; i++) {
        po[i] = po[i - 1] * 2 % mod;
    }

    scanf("%d", &N);
    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }

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

    if(N % 2) {
        for(int i = 0; i < N; i++) {
            if(arr[i] != ((i + 1) / 2) * 2) {
                printf("0");
                return 0;
            }
        }
    }
    else {
        for(int i = 0; i < N; i++) {
            if(arr[i] != (i / 2) * 2 + 1) {
                printf("0");
                return 0;
            }
        }
    }
    printf("%d", po[N / 2]);
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int a, b;
    string s;
    cin >> a >> b >> s;
    bool ans = true;
    for(int i = 0; i < a; i++){
        ans &= (s[i] >= '0' && s[i] <= '9');
    }
    ans &= s[a] == '-';
    for(int i = a+1; i < a+b+1; i++){
        ans &= (s[i] >= '0' && s[i] <= '9');
    }
    if(ans){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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


int main(void){
    
   int h,w;
   string s[111];
   cin>>h>>w;
   for(int i=0;i<h;i++)cin>>s[i];
   for(int i=0;i<h;i++){
       int co=0;
       for(int j=0;j<w;j++){
           if(s[i][j]=='.')co++;
       }
       if(co==w){
          for(int j=0;j<w;j++)s[i][j]='0'; 
       }
   }
   for(int j=0;j<w;j++){ 
       int co=0;
       for(int i=0;i<h;i++){
           if(s[i][j]=='.'|| s[i][j]=='0')co++;
       }
       if(co==h){
          for(int i=0;i<h;i++)s[i][j]='0'; 
       }
   }
   for(int i=0;i<h;i++){
       int co=0;
       for(int j=0;j<w;j++){
          if(s[i][j]!='0')cout<<s[i][j];
          else co++;
       }
       if(co!=w)cout<<endl;
   }
 
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


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

    int sa = b-a,l = 0;
    rep(i,1,sa+1)l += i;
    P(l-b);
    
	return  0;
}

Measured memory_bytes: 384
import numpy as np
n,d=map(int,input().split())
li=[list(map(int,input().split())) for _ in range(n)]
arr=np.array(li)
arr2=arr**2
count=0
for i in range(n):
    if arr2[i][0]+arr2[i][1]<=d**2:
        count=count+1
print(count)

Measured memory_bytes: 69816
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

ll dp[3030][3030][4];
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int R,C,K;
    cin >> R >> C >> K;
    vector<vector<ll>> A(R, vector<ll>(C,-1e18));
    rep(i,K) {
        int r,c,v; cin >> r >> c >> v;
        --r; --c;
        A[r][c] = v;
    }

    if (A[0][0] != -1e18) dp[0][0][1] = A[0][0];
    rep(x,R) {
        rep(y,C) {
            rep(i,4) {
                if (x < R-1) {
                    chmax(dp[x+1][y][0],dp[x][y][i]);
                    if (A[x+1][y] != -1e18) chmax(dp[x+1][y][1],dp[x][y][i]+A[x+1][y]);
                }
                if (y < C-1) {
                    chmax(dp[x][y+1][i],dp[x][y][i]);
                    if (A[x][y+1] != -1e18 and i < 3) {
                        chmax(dp[x][y+1][i+1],dp[x][y][i]+A[x][y+1]);
                    }
                }
            }
        }
    }

    ll ans = 0;
    rep(i,R) rep(j,C) rep(k,4) chmax(ans,dp[i][j][k]);

    cout << ans << ln;
}

Measured memory_bytes: 357752
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int main() {
  const int64_t mod = 1e9 + 7;
  const size_t maxN = 2 * 1e5;
  // 入力
  int N;
  cin >> N;
  vector<int> color(N);
  for (auto&& c : color) {
    cin >> c;
    c--;
  }
  // DP
  vector<int64_t> dp(N + 1);  // dp[i]でi未満の列を色ぬりした場合の数
  dp[0] = 1;
  vector<int64_t> tmp(maxN);
  for (int i = 0; i < N; i++) {
    dp[i + 1] = dp[i];
    if (i != 0 && color[i] != color[i - 1]) {
      dp[i + 1] = (dp[i + 1] + tmp[color[i]]) % mod;
    }
    tmp[color[i]] = dp[i + 1];
  }
  cout << dp[N] << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
using edge = struct {int to; ll cost;};

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)


//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
    int a, b;
    cin >> a >> b;
    int ans = 6 - a - b;
    cout << ans << "\n";
}

int main()
{
    solve();
    return 0;
}


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

int main() {
	string s;
	int x, y;
	cin >> s >> x >> y;

	vector<int> v;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'T') {
			v.push_back(cnt);
			cnt = 0;
		} else {
			cnt++;
		}
	}
	v.push_back(cnt);

	int size = s.size();
	vector<vector<bool>> d(v.size(), vector<bool>(size * 2 + 1, false));
	for (int i = 0; i < v.size(); i++) {
		if (i < 2) {
			d[i][v[i] + size] = true;
		}
		if (i == 1) {
			d[i][size - v[i]] = true;
		}
		if (i < 2) continue;

		for (int j = 0; j < d[i].size(); j++) {
			if (j - v[i] >= 0) {
				d[i][j] = d[i][j] | d[i - 2][j - v[i]];
			}
			if (j + v[i] < d[i].size()) {
				d[i][j] = d[i][j] | d[i - 2][j + v[i]];
			}
		}
	}

	int dx = v.size() - 2, dy = v.size() - 1;
	if (v.size() % 2 == 1) {
		dx = v.size() - 1;
		dy = v.size() - 2;
	}

	if (v.size() == 1) {
		if (d[dx][x + size] && (y == 0)) cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}

	if (d[dx][x + size] && d[dy][y + size]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 16128
#include<iostream>
using namespace std;
int n,m,dx[2]={0,1},dy[2]={1,0};char a[9][9];
struct data{int x,y;}que[1000];
void bfs()
{
  int h=0,t=1,xx,yy;
  que[0].x=que[0].y=1,a[1][1]='.';
  while(h!=t)
  {
    for(int i=0;i<2;i++)
    {
      xx=que[h].x+dx[i];
      yy=que[h].y+dy[i];
      if(xx<1||yy<1||xx>n||yy>m||a[xx][yy]=='.')continue;
      que[t].x=xx,que[t].y=yy,t++,a[xx][yy]='.';
      break;
    }
    h++;
  }
}
int main()
{
  cin>>n>>m;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
      cin>>a[i][j];
  bfs();
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
      if(a[i][j]=='#'){cout<<"Impossible"<<endl;return 0;}
  cout<<"Possible"<<endl;
  return 0;
}


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

int main(){
  long long X, A, B;
  cin >> X >> A >> B;
  if(A>=B){
    cout << "delicious" << endl;
    return 0;
  }else if(B-A<=X){
    cout << "safe" << endl;
    return 0;
  }
  cout << "dangerous" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
H = tuple(map(int, input().split()))
ans = 0
i = 0
ph = 0
for h in H:
    if ph >= h:
        i += 1
    else:
        ans = max(ans, i)
        i = 0
    ph = h
else:
    ans = max(ans, i)
print(ans)


Measured memory_bytes: 20772
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7

# 高速素因数分解(√n)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

lcd = dict()
for i in num:
  j = factorization(i)
  for x in j:
    if not x[0] in lcd.keys():
      lcd[x[0]] = x[1]
    else:
      lcd[x[0]] = max(lcd[x[0]],x[1])

lc = 1
for i,j in lcd.items():
  lc *= pow(i,j,mod)
  
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

ans =0
for i in range(n):
  ans += lc*modinv(num[i],mod)
  ans %= mod
print(ans)

Measured memory_bytes: 4596
using System.Text;
using System;

public class hello
{
    public static void Main()
    {
        var sb = new StringBuilder();
        var INF = " 1000000001";
        var INF2 = 1000000001;
        Console.ReadLine().Trim();
        string[] line = (Console.ReadLine().Trim() + INF).Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Console.ReadLine().Trim();
        line = (Console.ReadLine().Trim() + INF).Split(' ');
        var b = Array.ConvertAll(line, int.Parse);
        var p = 0; var q = 0;
        while (true)
        {
            if (a[p] == INF2 && b[q] == INF2) break;
            else if (a[p] < b[q]) sb.Append(string.Format("{0}\n", a[p++]));
            else if (a[p] > b[q]) sb.Append(string.Format("{0}\n", b[q++]));
            else if (a[p] == b[q]) { sb.Append(string.Format("{0}\n", a[p++])); q++; }
        }
        Console.Write(sb);
    }
}




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

int main()
{
    int n, sum_table[2][100]{}, max = 0;
    scanf("%d", &n);
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            scanf("%d", sum_table[i] + j);
        }
    }
    for (int i = 1; i < n; i++)
        sum_table[0][i] += sum_table[0][i - 1];
    for (int i = n - 2; i >= 0; i--)
        sum_table[1][i] += sum_table[1][i + 1];
    
    for (int i = 0; i < n; i++)
    {
        int tmp = sum_table[0][i] + sum_table[1][i];
        if (tmp > max) max = tmp;
    }
    printf("%d\n", max);

    return 0;
}

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

int mypow(int x, int y){
  int powe = 1;
  rep(i,y){
    powe *= x;
  }
  return powe;
}

int main(){
  int N, M;
  int c;
  int s;
  int num[3] = {-1, -1, -1};
  int flag = 1;

  cin >> N >> M;
  rep(i, M){
    cin >> s >> c;
    if(num[s-1] == -1) num[s-1] = c;
    else if(num[s-1] != c) flag = 0;
  }
  if(num[0] == 0)flag = 0;
  if(N == 1){
    if(num[0] == 0)flag = 1;
    else if (num[0] == -1) num[0] = 0;
  }

  int sum = 0;
  rep(i,N){
    if(num[0] == -1)num[0] = 1;
    else if(num[i] == -1)num[i] = 0;
    sum += mypow(10, N-i-1) * num[i];
    //cout << mypow(10, N-i-1) *num[i]<< endl;
  }

  if(flag)cout<<sum<<endl;
  else cout<<-1<<endl;

  return 0;
}

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

int main(void){
    int h, w, n;
    cin>>h>>w>>n;
    vector<int> v(n);
    int nowi=0;
    rep(i, n) cin>>v[i];
    vector<int> s(h*w);
    rep(i, n){
        rep(j, v[i]) s[nowi+j]=i+1;
        nowi+=v[i];
    }
    vector<vector<int> > ans(h, vector<int>(w));
    rep(i, h){
        if(i%2==0){
            rep(j, w) ans[i][j]=s[i*w+j];
        }
        else {
            rep(j, w) ans[i][w-1-j]=s[i*w+j];
        }
    }
    rep(i, h){
        rep(j, w) cout<<ans[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a[200010];
bool li[200010];

bool c(int t){
	REP(i,0,2*n-1) li[i]=(a[i]>=t); bool f=false;
	REP(i,0,2*n-2) if(li[i]==li[i+1]) f=true;
	
	bool used[2*n]={};
	if(f){
		queue<int> qu;
		qu.push((2*n-1)/2);
		
		while(!qu.empty()){
			auto p=qu.front(); qu.pop();
			if(used[p]) continue; used[p]=true;
			
			if(p-1>=0 and li[p]==li[p-1]) return li[p];
			if(p+1<2*n-1 and li[p]==li[p+1]) return li[p];
			if(p-1>=0) qu.push(p-1);
			if(p+1<2*n-1) qu.push(p+1);
		}
	}else{
		if(n%2) return li[(2*n-1)/2];
		else return !li[(2*n-1)/2];
	}
	
	return 0;
}

int binary_search(){
	int ok=1, ng=2*n-1;
	
	while(abs(ok-ng)>1){
		int mid=(ok+ng)/2;
		if(c(mid)) ok=mid;
		else ng=mid;
	}
	
	return ok;
}

int main(){
	cin >> n;
	REP(i,0,2*n-1) cin >> a[i];
	
	cout << binary_search() << endl;
	return 0;
}


Measured memory_bytes: 1408
X, N = map(int,input().split())
if N > 0:
  p = list(map(int, input().split()))
else:
  p=[]
#print(p)
p.sort()
#dis = p[0] - X
ans_1 = X
ans_2 = X
for i in range(N) :
  pi = p[i]
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for i in range(N) :
  pi = p[i]
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)

Measured memory_bytes: 9216
import java.util.*;

public class Main {

  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (A == 1) {
      if (B == 1) {
        System.out.println("Draw");
      } else {
        System.out.println("Alice");
      }
    } else if (B == 1) {
      System.out.println("Bob");
    } else if (A > B) {
      System.out.println("Alice");
    } else if (A == B) {
      System.out.println("Draw");
    } else {
      System.out.println("Bob");   
    }
  }
}

Measured memory_bytes: 20948
#include <stdio.h>

int main(){
	int N, l, r, i, ans = 0;
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d%d", &l, &r);
		ans += r - l + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int M,D;
        cin >> M >> D;
        int count = 0;
        int d1,d2;
        for(int m = 1;m <= M;m++)
        {
            for(int d = 1;d <= D;d++)
            {
                string dm = to_string(d);
                if(dm.size() != 1)
                {
                    d1 = dm[0] - '0';
                    d2 = dm[1] - '0';
                    if(d1 * d2 == m and d1 >= 2 and d2 >= 2)
                        count++;
                }
            }
        }
        cout << count << '\n';
}


Measured memory_bytes: 256
import numpy as np

mod = 998244353
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
S = sum(A)

# def fastpow(a, n):
#     i = 0
#     pow = [a]
#     while 1 << i <= n:
#         pow.append(pow[-1] * pow[-1] % mod)
#         i += 1
#     for j in range(i):


PS = [0 for i in range(N+1)]
for i in range(N):
    PS[i+1] = PS[i] + A[i]

# D1[i][r]: i個塗った時点でR=rとなる場合の数
D1 = np.zeros((N+1, S+1), dtype=int)
D1[0][0] = 1
# D2[i][r]: i個塗った時点でR=r, B=0となる場合の数
D2 = np.zeros((N+1, S+1), dtype=int)
D2[0][0] = 1

for i in range(N):
    D1[i+1] += D1[i] * 2
    D1[i+1][A[i]:] += D1[i][:-A[i]]
    D1[i+1] = D1[i+1] % mod

    D2[i+1] += D2[i]
    D2[i+1][A[i]:] += D2[i][:-A[i]]
    D2[i+1] = D2[i+1] % mod

border = (S + 1) // 2

result = 3 ** N
result -= 3 * sum(D1[N][border:])
if border * 2 == S:
    result += 3 * D2[N][border]

print(result % mod)


Measured memory_bytes: 433992
#include <cassert>
#include <algorithm>
#include <vector>

template<typename T>
struct FlowGraph {
private:
  struct edge {
    const int from, to;
    T cap;
    const int r_idx;
    const bool is_rev;
    edge(int f, int t, T c, int i, bool is_rev) :
      from(f), to(t), cap(c), r_idx(i), is_rev(is_rev) {}
  };

  std::vector<std::vector<edge>> G;

  T dfs(int v, int sink, T min_cap, std::vector<bool>& visited){
    visited[v] = true;
    if(v == sink) return min_cap;
    for(auto& e : G[v]){
      if(e.cap == T()) continue;
      if(visited[e.to]) continue;
      T min_cap_ = std::min(min_cap,e.cap);
      T flowed = dfs(e.to,sink,min_cap_, visited);
      if(flowed == T()) continue;
      e.cap -= flowed;
      G[e.to][e.r_idx].cap += flowed;
      return flowed;
    }
    return T();
  }
  
public:
  FlowGraph(size_t n) : G(n) {}
  void add_edge(int from, int to, T cap){
    int i = G[to].size(), i_ = G[from].size();
    G[from].emplace_back(from,to,cap,i,false);
    G[to].emplace_back(to,from,T(),i_,true);//reverse edge
  }
  T max_flow(int from, int to){
    T ret = 0, INF = 1e9;
    while(true){
      std::vector<bool> visited(G.size());
      T f = dfs(from,to,INF,visited);
      if(f == T()) break;
      ret += f;
    }
    return ret;
  }
  std::vector<edge> flowed_edge(){
    std::vector<edge> ret;
    for(auto v : G){
      for(auto e : v){
        if(e.is_rev) continue;
        if(!G[e.to][e.r_idx].cap) continue;
        ret.emplace_back(e.from,e.to,G[e.to][e.r_idx].cap,e.r_idx,false);
      }
    }
    return ret;
  }
};

#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<string> S(N);
  for(int i = 0; i < N; ++i){
    cin >> S[i];
  }
  FlowGraph<int> G(N*M+2);
  int source = N*M, sink = source+1;
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < M; ++j){
      if(S[i][j] == '#') continue;
      int v = i*M+j;
      if((i+j)%2){
        G.add_edge(source,v,1);
        if(i > 0 and S[i-1][j] != '#')
          G.add_edge(v,v-M,1);
        if(i < N-1 and S[i+1][j] != '#')
          G.add_edge(v,v+M,1);
        if(j > 0 and S[i][j-1] != '#')
          G.add_edge(v,v-1,1);
        if(j < M-1 and S[i][j+1] != '#')
          G.add_edge(v,v+1,1);
      }else{
        G.add_edge(v,sink,1);
      }
    }
  }
  cout << G.max_flow(source,sink) << '\n';
  auto flowed_edge = G.flowed_edge();
  int d[] = {M,-M,1,-1};
  string s = "v^><";
  for(auto e : flowed_edge){
    if(e.from == source) continue;
    if(e.to == sink) continue;
    for(int i = 0; i < 4; ++i){
      if(e.from+d[i] != e.to)
        continue;
      assert(S[e.from/M][e.from%M] == '.');
      assert(S[e.to/M][e.to%M] == '.');
      S[e.from/M][e.from%M] = s[i];
      S[e.to/M][e.to%M] = s[i^1];
      break;
    }
  }
  for(auto e : S)
    cout << e << '\n';
}


Measured memory_bytes: 5628
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    x = II()
    ans = x // 500 * 1000
    ans += (x % 500) // 5 * 5
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 38640
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    ll ans = 1e18;
    for(ll i=1;i*i<=N;i++){
        if(N%i==0){
            ans = min(ans,i+N/i);
        }
    }
    cout << ans-2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100100];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100100; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int par[100009],sz[100009];

int fin(int v) 
{
    if (v == par[v])    return v;
    return par[v] = fin(par[v]);
}

void uni(int a, int b) 
{
    a = fin(a);
    b = fin(b);
    if(a == b) return;
    if(sz[a] < sz[b]) swap(a, b);
    par[b] = a;
    sz[a] += sz[b];
}
void solve()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		sz[i]=1;
		par[i]=i;
	}
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		uni(x,y);
	}
	int ans=0;
	for(int i=1;i<=n;i++) if(fin(i)==i) ans++;
	cout<<ans-1<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 4436
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

void print(const vector<string> &page) {
	for(const auto &line : page) {
		cout << line << endl;
	}
	cout << "#" << endl;
}

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

	for(int plen, cnum, width, cspace; cin >> plen && plen;) {
		cin >> cnum >> width >> cspace;
		cin.ignore();

		const int len = cnum * width + cspace * (cnum - 1);
		vector<string> page(plen, string(len, '.'));

		int r = 0, c = 0;
		for(string line; getline(cin, line) && line != "?";) {
			bool first = true;

			while(first || line.size()) {
				string word;
				if(line.size() >= width) {
					word = line.substr(0, width);
					line = line.substr(width);
				}
				else {
					word = move(line);
					line = "";
				}

				const int offset = c * (width + cspace);
				copy(word.begin(), word.end(), page[r].begin() + offset);

				if(++r == plen) {
					r = 0;
					if(++c == cnum) {
						c = 0;
						print(page);
						fill(page.begin(), page.end(), string(len, '.'));
					}
				}

				first = false;
			}
		}

		if(any_of(page[0].begin(), page[0].end(), [](char c) { return c != '.';})) {
			print(page);
		}
		cout << "?" << endl;
	}

	return EXIT_SUCCESS;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<char> alp = {
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
    'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
    'U', 'V', 'W', 'X', 'Y', 'Z'
  };
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 26; j++) {
      if (s.at(i) == alp.at(j)) {
        s.at(i) = alp.at((j + n) % 26);
        break;
      }
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[100001];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	int lo = 1; int hi = n;
	int ans=0;
	while(lo<=hi)
	{
		int mid=(lo+hi)>>1;
		ll sum = 0;
		for(int i=mid-1;i<n;i++) sum+=a[i];
		bool pos=1;
		for(int i=mid-2;i>=0;i--)
		{
			if(a[i]<=2LL*sum)
			{
				sum+=a[i];
			}
			else
			{
				pos=false;break;
			}
		}
		if(pos)
		{
			lo=mid+1;
			ans=mid;
		}
		else
		{
			hi=mid-1;
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 2005
using namespace std;
int gcd(int a,int b)
{
    if(!b)return a;
    return gcd(b,a%b);
}
int mp[N][N];
int n,a[N],du[N],vis[N];
vector<int>v[N];
void ds(int x)
{
    vis[x]=1;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i]&&mp[x][i])
        {
            v[x].push_back(i);
            du[i]++;
            ds(i);
        }
    }
    return ;
}
priority_queue<int>q;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<i;j++)
            if(gcd(a[i],a[j])!=1)mp[i][j]=mp[j][i]=1;
    for(int i=1;i<=n;i++)if(!vis[i])ds(i);
    for(int i=1;i<=n;i++)if(!du[i])q.push(i);
    for(int i=1;i<=n;i++)
    {
        int tmp=q.top();q.pop();
        printf("%d ",a[tmp]);
        for(int j=0;j<v[tmp].size();j++)
        {
            du[v[tmp][j]]--;
            if(!du[v[tmp][j]])q.push(v[tmp][j]);
        }
    }
    return 0;
}


Measured memory_bytes: 16128
package main

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

func main() {
	N := ReadInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i], B[i] = ReadInt(), ReadInt()
	}
	sort.Ints(A)
	sort.Ints(B)
	if N%2 == 1 {
		fmt.Println(B[N/2] - A[N/2] + 1)
	} else {
		a1, b1 := A[N/2-1], B[N/2-1]
		a2, b2 := A[N/2], B[N/2]
		fmt.Println(b1 + b2 - a1 - a2 + 1)
	}
}

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 }


Measured memory_bytes: 8536
#include <bits/stdc++.h>
#define dbg(x) cerr<<#x<<" = "<<x<<endl;
#define dbg_v(v,n) {cerr<<#v<<" = [";for(int III=0;III<=n;III++)cerr<<v[III]<<(III!=n?",":"]\n");}
#define ll long long
#define ld long double
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define Nmax 102
using namespace std;

int n,fr[Nmax],x,mx,mn;

int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> x;
        fr[x]++;
        if (x > mx) mx = x;
    }
    if (mx==1){
        if (n==2) cout << "Possible\n";
        else cout << "Impossible\n";
        return 0;
    }
    mn = (mx+1) / 2;
    if (mx%2==0) mn++;
    for (int i=mx;i>=mn;i--){
        if (fr[i] < 2){
            cout << "Impossible\n";
            return 0;
        }
    }
    if (mx%2==0){
        mn--;
        if (fr[mn]!=1){
            cout << "Impossible\n";
            return 0;
        }
    }
    else{
        if (fr[mn]!=2){
            cout << "Impossible\n";
            return 0;
        }
    }
    for (int i=mn-1;i>=1;i--){
        if (fr[i]){
            cout << "Impossible\n";
            return 0;
        }
    }
    cout << "Possible\n";
    return 0;
}


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

A.sort()
stack = A[1:]
m = A[0]

while stack:
  stack = list(stack)
  l = []
  for x in stack:
    if x % m == 0:
      continue
    l.append(x % m)
  
  if not l:
    break
  l.append(m)
  m = min(l)
  stack = set(l)

print(m)


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define go(i,s) for(int i = head[s]; i; i = e[i].next)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const int maxn = 100050;

int a, b;

int main()
{
	cin >> a >> b;
	a = (a+b)%24;
	cout << a << endl;
	return 0;
}

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

using namespace std;
const int N = 2e5 + 3, MOD = 1e9 + 7;
long long f[N], cumNCK[N];
long long power(int b, int e) {
	long long ret = 1;
	while (e) {
		while (e % 2 == 0) {
			e /= 2;
			b = (1LL * b * b) % MOD;
		}
		--e;
		ret = (ret * b) % MOD;
	}
	return ret;
}
long long nCr(int n, int r) {
	assert(n >= r);
	return (f[n] * power((f[r] * f[n - r]) % MOD, MOD - 2)) % MOD;
}
int n, k, a[N];
int main() {
//	freopen("input.in", "r", stdin);
	f[0] = 1;
	for (int i = 1; i < N; ++i)
		f[i] = (f[i - 1] * i) % MOD;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	if (k == 1) {
		puts("0");
		return 0;
	}
	sort(a, a + n);
	for (int i = 0; i <= n * 2; ++i) {
		if (k - 2 <= i) {
			if (i)
				cumNCK[i] = (cumNCK[i - 1] + nCr(i, k - 2)) % MOD;
			else
				cumNCK[i] = nCr(i, k - 2);
//			cout << nCr(i, k - 2) << " " << cumNCK[i] << endl;
		}
	}
	long long res = 0;
	for (int i = n - 1; i >= 0; --i) {
		int len = i - k + 2;
//		cout << a[i] << " " << len << ", ";
		if (len >= 0) {
			res = (res + a[i] * cumNCK[len + k - 2 - 1]) % MOD;
		}
//		cout << endl;
		len = n - (i + k) + 1;
		if (len >= 0) {
			res = ((res - a[i] * cumNCK[len + k - 2 - 1]) % MOD + MOD) % MOD;
//			cout << a[i] << " " << len << endl;
		}
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, k;
    string s;
    cin >> n >> k >> s;
    
    int left = 0, right = 0, pos = 0, cnt = 0, rest = k;
    bool flag = true;
    queue<int> border;
    int res = 0;
    while(pos < n){
        if(flag){   // 直前が 1
            if(s[pos] == '1'){
                ++cnt;
            }
            else{   // s[pos] == '0'
                if(rest == 0){
                    chmax(res, cnt);
                    right = border.front();
                    border.pop();
                    cnt -= right - left;
                    left = right;
                }
                else    --rest;
                ++cnt;
                flag = false;
            }
        }
        else{       // 直前が 0
            if(s[pos] == '0'){
                ++cnt;
            }
            else{   // s[pos] == '1'
                ++cnt;
                flag = true;
                border.push(pos);
            }
        }
        ++pos;
    }
    chmax(res, cnt);
    cout << res << endl;
}

Measured memory_bytes: 512
#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;
}

signed main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}



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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    for(int i=a;i<=b;i++) {
        if(i%k==0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}


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

int main(){
  long long N,num,ans=1,was=0,temp=1,i,cnt=0;
  bool chk=false;
  cin>>N>>num;
  if(N==1){
    cout<<num<<endl;
    return 0;
  }
  while(num!=0){
 	for(i=2;i<=num;i++){
 		if(num%i==0 && num!=2){
			chk=true;
			break;
		}
		if(num/i<i || num==2){
			chk=false;
			break;
		}
 	}
	if(chk==true){
	  if(was==i)temp++;
      else temp=1;
      was=i;
      if(temp>=N){
        ans*=i;
        temp=0;
      }
	}else{
	  if(was==num)temp++;
      if(temp>=N){
        ans*=num;
        temp=0;
      }
	  break;
	}
	num=num/i;
	cnt++;
  }
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

int main() {
  ll L, R;
  cin >> L >> R;
  R = min(R, L + 4038);
  ll res = 2018;
  for (ll i = L; i <= R; ++i) {
    for (ll j = i + 1; j <= R; ++j) {
      res = min(res, (i * j) % 2019);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  int x, a, b, aa, bb;
  char cc;
  cin >> x >> a >> b;
  aa = x-a;
  aa = aa>0?aa:-aa;
  bb = x-b;
  bb = bb>0?bb:-bb;
  cc = aa<bb?'A':'B';
  cout << cc << endl;
}


Measured memory_bytes: 256