akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		Deque<int[]> quque = new ArrayDeque<int[]>();
		
		while(true) {
			String str = br.readLine();
			int sPos = str.indexOf(" ");
			int w = Integer.parseInt(str.substring(0, sPos));
			int h = Integer.parseInt(str.substring(sPos+1));
			if(w == 0 && h == 0) break;
			
			int[][] map = new int[h][w];
			int[] personXY = new int[2];
			for(int y = 0; y < h; y++) {
				str = br.readLine();
				
				for(int x = 0; x < w; x++) {
					char c = str.charAt(x);
					if(c == '@') {
						personXY[0] = x;
						personXY[1] = y;
					}
					else
						map[y][x] = c == '.' ? 0
						          : c == '#' ? 1 : 2;
				}
			}
			//System.out.println(Arrays.deepToString(map));
			
			quque.addLast(personXY);
			
			int movable = 0;
			
			while(!quque.isEmpty()) {
				int[] xy = quque.pollFirst();
				int x = xy[0];
				int y = xy[1];
				
				if(map[y][x] == 1)
					continue;
				
				map[y][x] = 1;
				movable++;
				if(0 < x && map[y][x-1] == 0) {
					quque.addLast(new int[]{x-1, y});
				}
				if(x+1 < map[y].length && map[y][x+1] == 0) {
					quque.addLast(new int[]{x+1, y});
				}
				if(0 < y && map[y-1][x] == 0) {
					quque.addLast(new int[]{x, y-1});
				}
				if(y+1 < map.length && map[y+1][x] == 0) {
					quque.addLast(new int[]{x, y+1});
				}
			}
			
			
			System.out.println(movable);
		}
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int count(string s) {
  int cnt = 0;
  rep(i, s.size()) {
    if (i != (int)s.size()-1) {
      if (s[i] == 'P' and s[i] == 'D') {
	cnt++;
      }
    }
    if(s[i] == 'D') {
      cnt++;
    }
  }
  return cnt;
}

int main(){
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }

  cout << s << endl;
}


Measured memory_bytes: 3752
def main():
    s = input()
    w = "ATCG"

    def f(ss):
        c = 0
        for i in range(len(ss)):
            if ss[i] not in w:
                return c
            c += 1
        return c

    res = 0
    for i in range(len(s)):
        res = max(res, f(s[i:]))
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 200010
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define F first
#define S second
 
#define ll 	long long int
 
#define mod  1000000007
 
 map<ll, ll> mp;
 
int main()
{
	FAST;
	ll n;
	cin >> n;
	ll a[n+6];
	
	for(ll i = 0; i < n; i++){
		cin >> a[i];
	}
	ll ans = 0;
	sort(a, a + n);
	 for(ll i = 0; i < n - 2; i++){
        for(ll j = i + 1; j < n - 1; j++){
            for(ll k = j + 1; k < n; k++){
                ll x = a[i];
                ll y = a[j];
                ll z = a[k];
                if((x + y) > z && (z - y) < x && x != y && x != z && y != z)
                    ans++;
            }
        }
    }
	cout << ans;
	return 0;
}

Measured memory_bytes: 3668
s = input()
t = input()

x = len(s)
y = len(t)
list1 = []
for i in range(x-y+1):
    z = s[i:i+y]
    count = 0
    for n in range(y):
        if z[n] == t[n]:
            count += 1
    list1.append(count)

saidai = max(list1)

saisyo = y - saidai

print(saisyo)


Measured memory_bytes: 9096
#include <bits/stdc++.h>
#define int long long
const int MOD=1e9+7;
using pii=std::pair<int,int>;
using namespace std;

const int maxn =  2e5 + 5;

int n, a[maxn], vis[maxn] = {0}, k;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    deque<int> cycle;
    int cur = 1;
    while(!vis[cur])
    {
        cycle.push_back(cur);
        vis[cur] = 1;
        cur = a[cur];
    }
    if(k < cycle.size())
        cout << cycle[k] << "\n";
    else 
    {
        while(!cycle.empty() && cycle.front() != a[cycle.back()])
        {
            k--;
            cycle.pop_front();
        }
        cout << cycle[k % cycle.size()] << "\n";
    }
    return 0;
}

Measured memory_bytes: 7952
#include <stdio.h>

int main(void)
{
	int a, b;
	int sum;
	int keta;
	
	while (scanf("%d %d", &a, &b) != EOF){
		sum = a + b;
		keta = 1;
		while (sum / 10 != 0){
			sum /= 10;
			keta++;
		}
		
		printf("%d\n", keta);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
string a,b;
int main()
{
	cin >> a >> b;
	int al = a.length();
	int bl = b.length();
	for (int i = 0;i < bl;i++)
	{
		cout << a[i] << b[i];
	} 
	if (al > bl) cout << a[bl] << endl;
	cout << endl;
	return 0;
}

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

#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long int lli;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define Yes_RTN s_cout("Yes");return 0
#define No_RTN  s_cout("No");return 0
#define YES_RTN s_cout("YES");return 0
#define NO_RTN  s_cout("NO");return 0


int i_cins(int n, int* A);
int l_cins2(int n, long* A,long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);


int main(void) {

	int     N,A,i,cnt=0;

	i_cin(N);
	rept (i,0,N){
		i_cin(A);
		if (A % 2) cnt++;
	}
	if (cnt % 2) { NO_RTN; }
	YES_RTN;
}
	
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a -*(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	rept(i, 0, n) {
		i_cin(*(a + i));
	}

	return 0;
}




Measured memory_bytes: 128
#include<stdio.h>
#include <string.h>
char O[510], E[500], a[1010], c;
int main()
{
    int i, j;
    scanf("%s%s", O, E);
    j = 0;
    int lo=strlen(O);
    int le=strlen(E);
    for(i = 0; i<lo; i++)
    {
        a[j] = O[i];
        j += 2;
    }
    j = 1;
    for(i = 0; i<le; i++)
    {
        a[j] = E[i];
        j += 2;
    }
    a[j] = '\0';
    printf("%s", a);
}

Measured memory_bytes: 128
def gcd(a,b):
    if a%b == 0:
        return b
    else :
        return gcd(b,a%b)

k = int(input())

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for h in range(1,k+1):
            t = gcd(i,j)
            t = gcd(t,h)
            ans += t
print(ans)


Measured memory_bytes: 75152
#include <iostream>
#include <vector>

using namespace std;

#define MAX_N 101

typedef long long int int64;

typedef struct
{
	int64 rt_r;
	int64 rt_b;
	int64 con_r;
	int64 con_b;
} bar;

bar btemp;
bar* makebar(const int64 rt_r,const int64 rt_b,const int64 con_r,const int64 con_b)
{
	btemp.rt_r = rt_r;
	btemp.rt_b = rt_b;
	btemp.con_r = con_r;
	btemp.con_b = con_b;
	return &btemp;
}

int64 gcd(int64 a,int64 b)
{
	int64 tmp;
	if(a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	while(b != 0)
	{
		tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}

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

int64 N;
vector<bar> B;
vector<bool> T;
vector<int64> A;

void dfs(int64 _b,int64 _u,int64 _d)
{
	int64 u = _u / gcd(_u,_d);
	int64 d = _d / gcd(_u,_d);
	int64 b = _b - 1;
	if(B[b].con_r != 0)
	{
		dfs(B[b].con_r,u * B[b].rt_b,d * (B[b].rt_b + B[b].rt_r));
	}
	else
	{
		A.push_back((d * (B[b].rt_b + B[b].rt_r)) / gcd((u * B[b].rt_b),(d * (B[b].rt_b + B[b].rt_r))));
	}
	if(B[b].con_b != 0)
	{
		dfs(B[b].con_b,u * B[b].rt_r,d * (B[b].rt_b + B[b].rt_r));
	}
	else
	{
		A.push_back((d * (B[b].rt_b + B[b].rt_r)) / gcd((u * B[b].rt_r),(d * (B[b].rt_b + B[b].rt_r))));
	}
}

int main(void)
{
	while(true)
	{
		cin >> N;
		A.clear();
		B.clear();
		T.clear();
		if(N == 0)
			exit(0);
		int64 p,q,r,b;
		for(int64 i = 0;i < N;i++)
		{
			cin >> p >> q >> r >> b;
			B.push_back(*makebar(p / gcd(p,q),q / gcd(p,q),r,b));
			T.push_back(true);
		}
		for(auto itr = B.begin();itr < B.end();itr++)
		{
			if(itr->con_r != 0)
				T[itr->con_r-1] = false;
			if(itr->con_b != 0)
				T[itr->con_b-1] = false;
		}
		int64 top = -1;
		for(auto itr = T.begin();itr < T.end();itr++)
		{
			if(*itr)
				top = itr - T.begin();
		}
		if(top == -1)
			exit(-1);
		dfs(top+1,1,1);
		int64 result = 1;
		for(auto itr = A.begin();itr < A.end();itr++)
		{
			result = lcm(result,*itr);
		}
		cout << result << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7;
const int gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int N = 3e5 + 5;
int preE[N];
int preW[N];
string f;
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int n;
        cin >> n;
        cin >> f;
        preE[0] = preW[0] = 0;
        for (int i = 1; i <= n; i++)
        {
                if (f[i - 1] == 'W')
                {
                        preW[i] = preW[i - 1] + 1;
                        preE[i] = preE[i - 1];
                }
                else
                {
                        preE[i] = preE[i - 1] + 1;
                        preW[i] = preW[i - 1];
                }
        }
        ll anser = INT_MAX;
        ll now;
        for (int i = 1; i <= n; i++)
        {
                now = preW[i - 1] - preW[0];
                now += preE[n] - preE[i];
                anser = min(anser, now);
        }
        cout << anser;
        return 0;
}


Measured memory_bytes: 2964
<?php
$input_line = fgets(STDIN);
$array = explode(" ", $input_line);
$W = $array[0];
$a = $array[1];
$b = $array[2];
//fscanf(STDIN, "%d %d %d", $W $a $b);
if ($a + $W >= $b && $a <= $b or $b + $W >= $a && $b <= $a) {
  echo 0;
} elseif ($a <= $b) {
  echo $b - ($a + $W);
} else {
  echo $a - ($b + $W);
}
?>


Measured memory_bytes: 3828
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};

Int n;
vector<string> que;
void dfs(string s,char k) {
   // cout << s << endl;
    if (s.size() == n) {
        que.push_back(s);
        return;
    }
    for (int i = 0; i <= k;i++){
        dfs(s + (char)('a'+i),i+1);
    }
}
int main(void) {
    set<char> s;
    Int n;
    cin >> n;
    REP(n,i){
        char z;
        cin >> z;
        s.insert(z);
    }
    Int a = max((Int)s.size(),(Int)3);
    if (a == 3) {
        cout << "Three" << endl; 
    }else{
        cout << "Four" << endl;
    }
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;




int main() {

    
    string s;
    cin >> s;

    if (s[0] == 'A' && s[1] == 'A' && s[2] == 'A') cout << "No" << endl;
    else if (s[0] == 'B' && s[1] == 'B' && s[2] == 'B') cout << "No" << endl;
    else cout << "Yes" << endl;







}




//              g++ -std=c++1z


























Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
using namespace std;

const int N = 3e5;
const int inf = 1e9;

int n, t, a[N];
ll ans, f[505][2][2];

int main() {
	cin >> n;
	while (n) {
		a[++t] = n % 10;
		n /= 10;
	}
	for (int cnt = 1000; cnt >= 1; cnt--) {
		memset(f, 0, sizeof(f));
		n = (cnt + 1) / 2;
		if (cnt < t) continue;
		f[0][0][0] = 1;
		for (int i = 1; i <= n; i++) {
			if (cnt % 2 && i == n) { 
				for (int jj = 0; jj <= 1; jj++) {
					for (int kk = 0; kk <= 1; kk++) {
						if (f[i - 1][jj][kk] == 0) continue;
						for (int j = 0; j <= 9; j++) {
							if (i == 1 && j == 0) continue;
							int t = jj * 10 - kk;
							if (t == a[i]) ans += f[i - 1][jj][kk];
						}		
					}
				}
			} else {
				for (int jj = 0; jj <= 1; jj++) {
					for (int kk = 0; kk <= 1; kk++) {
						if (f[i - 1][jj][kk] == 0) continue;
						for (int k = 0; k <= 9; k++) {
							if (i == 1 && k == 0) continue;
							for (int j = 0; j <= 9; j++) {
								int t1 = j - k + jj * 10;
								int t2 = k - j - kk;
								for (int jjj = 0; jjj <= 1; jjj++) {
									for (int kkk = 0; kkk <= 1; kkk++) {
										if (t1 - jjj != a[cnt - i + 1]) continue;
										if (t2 + kkk * 10 != a[i]) continue;
										f[i][jjj][kkk] += f[i - 1][jj][kk];
									}
								}
							}
						}		
					}
				}
			}
		}
		if (cnt % 2 == 0) {
			ans += f[n][0][0];
			ans += f[n][1][1];
		}
	}
	cout << ans;
}




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

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

    //素因数分解
    vector<pair<ll,int>> fs;
    //1~sqrt(n)の範囲で分解
    for(ll i=2;i*i<=n;i++){
        int tmp = 0;    //指数部分
        while(n%i==0){
            n /= i;
            tmp++;
        }
        fs.push_back(make_pair(i,tmp));
    }
    //最後に残るのは1かsqrt(n)以上の素因数一つ
    if(n!=1) fs.push_back(make_pair(n,1));

    int ans = 0;
    for(auto p: fs){
        int q = p.second;
        int sub = 1;
        while(q>=sub){
            q -= sub;
            sub++;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int alice = 0, bob = 0;
    rep(i, n)
    {
        if (i % 2 == 0)
            alice += a[i];
        else
            bob += a[i];
    }
    cout << alice - bob << endl;
    return 0;
}


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

#define _GLIBCXX_DEBUG

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  for(int h = 0; h < H; h++) {
    for(int w = 0; w < W; w++) {
      cin >> table.at(h).at(w);
    }
  }

  vector<bool> hflag(H,true);
  vector<bool> wflag(W,true);

  // 行列チェック
  for(int h = 0; h < (int)table.size(); h++) {
    for(int w = 0; w < (int)table.at(0).size(); w++) {
      if( table.at(h).at(w) == '#') {
        hflag.at(h) = false;
        wflag.at(w) = false;
      }
    }
  }

  // falseのときはスキップして出力
  for(int h = 0; h < (int)table.size(); h++){
    if(hflag.at(h)) continue;
    for(int w = 0; w < (int)table.at(h).size(); w++){
      if(wflag.at(w)) continue;
      cout << table.at(h).at(w);
    }
    cout << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    ll n,W;
    cin >> n >> W;
    vector<ll> w(n+1,0),v(n+1,0);
    for(int i = 1; i <= n; i++){
        cin >> w[i] >> v[i];
    }

    vector<vector<ll> > dp(n+1);
    for(int i = 0; i <= n; i++){
        dp[i].resize(W+1,0);
    }

    for(int i = 1; i <= n; i++){
        for(int j = W; j >=0; j--){
            dp[i][j] = max(dp[i-1][j],(j-w[i]>=0?dp[i-1][j-w[i]]+v[i]:0));
        }
    }

    cout << dp[n][W] << endl;


    return 0;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

int main()
{
  string D;

  cin >> D;

  if(D == "25"){
        cout << "Christmas" << endl;
      }else if(D == "24"){
        cout << "Christmas Eve" << endl;
      }else if(D == "23"){
        cout << "Christmas Eve Eve" << endl;
      }else{
        cout << "Christmas Eve Eve Eve" << endl;
      }
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N, K = in_nn()
    readline()

    if K == 2:
        print(N - 1)
        exit()

    q, r = divmod(N, K - 1)
    if r in (0, 1):
        ans = q
    else:
        ans = q + 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10284
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            (long K, long S) = Slice2<long>();
            var ans = 0L;
            for (var i = 0; i <= K; ++i)
            {
                for (var j = 0; j <= K; ++j)
                {
                    if (i + j <= S && S - (i + j) <= K)
                        ++ans;
                }
            }
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27372
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;

struct Card {
    char suit;
    int value;
};

void bubblesort(struct Card A[], int N){
    int flag = 1;
    while(flag){
        flag = 0;
        for(int j = N-1; j > 0; j--){
            if (A[j].value < A[j-1].value){
                swap(A[j], A[j-1]);
                flag = 1;
            }
        }
    }
}

void selectionsort(struct Card A[], int N){
    for(int i=0; i<N; i++){
        int minj = i;
        for(int j=i; j<N; j++){
            if (A[j].value < A[minj].value) minj =j;
        }
        if(i != minj){
            swap(A[i], A[minj]);
        }
    }
}

void presentation_card(struct Card A[], int N){
    for(int i=0; i<N; i++){
        if(i > 0) printf(" ");
        printf("%c", A[i].suit);
        printf("%d", A[i].value);
    }
    printf("\n");
}



int main(){
    //?????°?????£?¨?
    Card A1[36];
    Card A2[36];
    int N;
    bool stable = true;

    //?????????????????????
    scanf("%d", &N);
    for(int i = 0; i < N; i++) scanf(" %c%d", &A1[i].suit, &A1[i].value);
    for(int i = 0; i < N; i++) A2[i] = A1[i];

    //?????????


    //??¢?????´?????????
    bubblesort(A1, N);
    selectionsort(A2, N);
    for (int i=0; i<N; i++){
        if (A1[i].suit != A2[i].suit) stable = false;
    }


    //??????
    presentation_card(A1, N);
    printf("Stable\n");
    presentation_card(A2, N);
    if (stable) printf("Stable\n");
    else printf("Not stable\n");
    return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  ll l=1, r=big, m;
  ll num;
  while(l<r) {
    m = (l+r)/2;
    num = 0;
    for(int i=0;i<N;++i) {
      if(A[i]%m==0) num += A[i]/m-1;
      else num += A[i]/m;
    }
    if(num<=K) r = m;
    else l = m+1;
  }
  cout<<l<<endl;
}

Measured memory_bytes: 5064
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


n = ip()                              #入力整数1つ
#x,y= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s = 0
while (1):
    for i in range(n):
        if a[i]%2:
            print(s)
            exit(0)
        else :a[i]/=2
    s+=1

Measured memory_bytes: 13380
import Data.List
import Data.Maybe

main :: IO ()
main = do
  s <- getLine
  k <- readLn :: IO Integer
  let none = filter (/='1') s
      noneId = findIndex (/='1') s

  putChar $ if null none
    then '1'
    else if fromJust (noneId) < fromIntegral k 
      then head none
      else '1'

  putStrLn ""

Measured memory_bytes: 508
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;

int n, k, p[N], ans, ch;

int main() {
	//ifstream cin("10.txt");
	//ofstream cout("esme_soal.out");
	cin >> n >> k;
	cout << setprecision(30);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]++;
	}
	for (int i = 0; i < k; i++)
		ch += p[i];
	ans = ch;
	for (int i = k; i < n; i++) {
		ch += p[i] - p[i - k];
		ans = max(ans, ch);
	}
	cout << 1. * ans / 2 << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define int long long

signed main() {

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

    int n, m; cin >> n >> m;
    priority_queue<int> q;
    rep(i,n) {int a; cin >> a; q.push(a);}
    rep(i,m) {int a = q.top(); q.pop(); q.push(a/2);}
    int ans = 0;
    rep(i,n) {ans += q.top(); q.pop();}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4228
import math
N,M=map(int,input().split())
n=0
m=0
def combinations_count(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if N>1:
	n=combinations_count(N, 2)
if M>1:
	m=combinations_count(M, 2)
print(n+m)

Measured memory_bytes: 3060
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    x = 0
    y = sum(a)
    res = []
    for i in range(n-1):
        x += a[i]
        y -= a[i]
        res.append(abs(x - y))

    return min(res)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 24064
(X,) = [int(x) for x in input().split()]

M = 10 ** 5
fifthRoot = {}
for i in range(-M, M + 1):
    fifthRoot[i ** 5] = i

for b5 in fifthRoot.keys():
    if b5 + X in fifthRoot:
        a5 = b5 + X
        a = fifthRoot[a5]
        b = fifthRoot[b5]
        assert a ** 5 - b ** 5 == X
        print(a, b)
        exit()


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

string s;
int a[26];
long long ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> s;
	for (int i = 0; i < (int)s.size(); ++i) {
		a[s[i] - 'a']++;
	}	
	for (int i = 0; i < 26; ++i) {
		for (int j = i + 1; j < 26; ++j) ans += 1LL * a[i] * a[j];
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
int n,A[100007];
int main() {
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&A[i]);
	sort(A+1,A+1+n);
	printf("%d",A[n/2+1]-A[n/2]);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

bool is_prime[1000010];
int main() {
    int x;
    cin >> x;
    if(x >= 400 && x <= 599) cout << 8 << endl;
    else if(x >= 600 && x <= 799) cout << 7 << endl;
    else if(x >= 800 && x <= 999) cout << 6 << endl;
    else if(x >= 1000 && x <= 1199) cout << 5 << endl;
    else if(x >= 1200 && x <= 1399) cout << 4 << endl;
    else if(x >= 1400 && x <= 1599) cout << 3 << endl;
    else if(x >= 1600 && x <= 1799) cout << 2 << endl;
    else if(x >= 1800 && x <= 1999) cout << 1 << endl;
    return 0;
}

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

int main(){

  int n, wh;
  int v[1001] = {};
  int w[1001] = {};
  int dp[101][10001] = {};

  cin >> n >> wh;
  for(int i = 0; i < n; i++){
    cin >> v[i] >> w[i];
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= wh; j++){
      if(j < w[i]){
        dp[i+1][j] = dp[i][j];
      }else{
        dp[i+1][j] = max(dp[i][j], dp[i+1][j - w[i]] + v[i]);
      }
    }
  }
  cout << dp[n][wh] << endl;
  return 0;
}


Measured memory_bytes: 7012
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <complex>
#include <utility>
#include <cstring>
#include <iostream>
#include <assert.h>
#include <algorithm>
using namespace std;
#define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define ll long long
#define ull unsigned ll
#define db double
#define lb long db
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define com complex<db>
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define cle(x) memset(x,0,sizeof(x))
#define lowbit(x) (x&(-x))
#define fo(i,j,k) for(int i=(j),end_i=(k);i<=end_i;i++)
#define fd(i,j,k) for(int i=(j),end_i=(k);i>=end_i;i--)

const ll mod=998244353;//module
template<typename T>
inline void Add(T &x,T y){x+=y; if(x>=mod) x-=mod;}
template<typename T>
inline void Mul(T &x,T y){(x*=y)%=mod;}
inline int read()
{
	int x=0; char ch=getchar(); bool f=0;
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
	return f?-x:x;
}
#define N 200010

struct node{
	int l,r;
	friend inline bool operator<(const node &A,const node &B)
	{
		if(A.l!=B.l) return A.l<B.l;
		return A.r<B.r;
	}
}q[N];

int tag[N<<1],mx[N<<1],ls[N<<1],rs[N<<1],cnt;
inline void pushtag(int u,int x)
{
	tag[u]+=x; mx[u]+=x;
}
inline void pushdown(int u)
{
	if(!tag[u]) return;
	if(ls[u]) pushtag(ls[u],tag[u]);
	if(rs[u]) pushtag(rs[u],tag[u]);
	tag[u]=0;
}
int build(int l,int r)
{
	int u=++cnt;
	if(l==r) {mx[u]=r; return u;}
	int mid=l+r>>1;
	ls[u]=build(l,mid);
	rs[u]=build(mid+1,r);
	mx[u]=max(mx[ls[u]],mx[rs[u]]);
	return u;
}
void add(int u,int l,int r,int L,int R,int x)
{
	if(L<=l&&r<=R) return pushtag(u,x);
	pushdown(u);
	int mid=l+r>>1;
	if(L<=mid) add(ls[u],l,mid,L,R,x);
	if(mid<R)  add(rs[u],mid+1,r,L,R,x);
	mx[u]=max(mx[ls[u]],mx[rs[u]]);
}
int ask(int u,int l,int r,int L,int R)
{
	if(L<=l&&r<=R) return mx[u];
	pushdown(u);
	int mid=l+r>>1,ans=0;
	if(L<=mid) ans=max(ans,ask(ls[u],l,mid,L,R));
	if(mid<R)  ans=max(ans,ask(rs[u],mid+1,r,L,R));
	return ans;
}
int n,m,ans;
int main()
{
	n=read(); m=read();
	fo(i,1,n) q[i].l=read(),q[i].r=read();
	build(0,m+1);
	sort(q+1,q+n+1);
	ans=max(0,n-m);
	for(int i=1,j=0;j<=m;j++)
	{
		for(;i<=n&&q[i].l==j;i++) add(1,0,m+1,0,q[i].r,1);
		ans=max(ans,-(j+m+1)+mx[1]);
	}
	printf("%d",ans);
	return 0;
}

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

// one-based numbering
struct UnionFind {
    vector<int> data;
    // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
    UnionFind(int n) {
        data.resize(n+1, -1);
    }
    int find(int x) {
        if(data[x] < 0) return x;
        else return data[x] = find(data[x]);
    }
    int size(int x) {
        return -data[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, k; cin >> n >> m >> k;
    vector<int> fc(n+1, 0), ic(n+1, 0);
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        fc[a]++, fc[b]++;
        uf.unite(a, b);
    }
    for (int i = 0; i < k; i++) {
        int c, d; cin >> c >> d;
        if (uf.same(c, d)) ic[c]++, ic[d]++;
    }
    for (int i = 1; i <= n; i++) {
        if (i != 1) cout << " ";
        cout << uf.size(i) - fc[i] - ic[i] - 1;
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 2048
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll i, ll z) {
	ll sum = 1;
	for (ll j = max(z, 2LL); j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%Mod;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int s = 0;
	H a = { 0,0 };
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int t;
		H x;
		cin >> t >> x.x >> x.y;
		int sum = abs(a.x - x.x) + abs(a.y - x.y);
		t = t - s;
		sum = t - sum;
		if (sum < 0) {
			cout << "No\n";
			return 0;
		}
		if (sum % 2 == 1) {
			cout << "No\n";
			return 0;
		}
		s = s + t; a = x;
	}
	cout << "Yes\n";
	getchar(); getchar();
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
MOD = 10 ** 9 + 7

s = "ATGC"
t = ["AGC", "ACG", "GAC"]
d = [defaultdict(int), {x+y+z: 1 for x in s for y in s for z in s if x+y+z not in t}]
# d = [{"": 1}, defaultdict(int)]

# print(d[0])
for i in range(4, n+1):
    a = i%2
    b = (i-1)%2

    d[a] = defaultdict(int)
    for k in d[b]:
        for c in s:
            if "AGC" not in [k[1:]+c, k[0]+k[2]+c, k[2]+k[1]+c, k[1]+c+k[2], k[0]+k[1]+c]:
                d[a][k[1:]+c] += d[b][k]
                d[a][k[1:]+c] %= MOD

print(sum(d[n%2].values()) % MOD)


Measured memory_bytes: 3316
n=int(input())
l=list(map(int, input().split()))
te=True
for i in range(n):
    if l[i]%2==0:
        if l[i]%3!=0 and l[i]%5!=0:
            te=False
            break

if te==True:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int n;
int dp[1000005],tohop[1000005],ans;
int pew(int x,int y,int p){
	int res=1;
	x%=p;
	while(y>0){
		if(y%2) res=(res*x)%p;
		y/=2;
		x=(x*x)%p;
	}
	return res;
}
int fuck(int n,int p){
	return pew(n,p-2,p);
}
int solve(int n,int k){
	if(n<k) return 0;
	if(k==0) return 1;
	return (tohop[n]*fuck(tohop[k],mod)%mod*fuck(tohop[n-k],mod)%mod)%mod;
}
signed main(){
	scanf("%lld",&n);
	dp[2]=1,tohop[0]=1;
	for(int i=1;i<=1000000;i++){
		tohop[i]=tohop[i-1]*i%mod;
	}
	for(int i=n/2;i<n;i++){
		dp[i]=solve(i-1,n-i-1)*tohop[i]%mod*tohop[n-i-1]%mod;
		ans=(ans+(dp[i]-dp[i-1]+mod)*i%mod)%mod;
	}
	printf("%d",ans%mod);
}

Measured memory_bytes: 13824
table = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    table[b-1][f-1][r-1] += v
for i in range(4):
    for j in range(3):
        print(" " + " ".join(map(str, table[i][j])))
    if i != 3:
        print("#" * 20)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S, ans = "";
    cin >> S;


    vector<int> alpha(26, 0);
    rep(i, S.size()) {
        alpha[S[i] - 'a']++;
    }

    int cnt = 0;
    string m = "";
    bool flag = false;
    
    rep(i, 26) {
        cnt += alpha[i];
        if (alpha[i] == 0) m += (char)(i + 'a');
    }
    if (cnt != 26) {
        ans += S + m[0];
        flag = true;
    }
    else {
        for (int i = (int)S.size() - 1; i >= 0; i--) {
            int index = (int)(S[i] - 'a');
            if (flag) ans += S[i];
            else {
                repd(i, index + 1, 26) {
                    if (alpha[i] == 0) {
                        ans += (char)('a' + i);
                        flag = true;
                        break;
                    }
                }
            }
            alpha[index] = 0;
        }
        reverse(all(ans));
    }

    cout << (flag ? ans : "-1") << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod = 998244353;
typedef pair<int, int> P;
typedef pair<int, P> PP;
string s[105];
int dp[105][105];
int dx[] = { 0,1 }, dy[] = { 1,0 };
signed main() {
	int h, w; cin >> h >> w;
	rep(i, h)cin >> s[i];
	rep(i, h)rep(j, w)dp[i][j] = inf;
	priority_queue<PP>Q;
	if (s[0][0] == '.') {
		Q.push(PP(0, P(0, 0)));
		dp[0][0] = 0;
	}
	else {
		Q.push(PP(1, P(0, 0)));
		dp[0][0] = 1;
	}
	while (Q.size()) {
		PP p = Q.top(); Q.pop();
		int d = p.first, ni = p.second.first, nj = p.second.second;
		if (d > dp[ni][nj])continue;
		rep(j, 2) {
			int mi = ni + dx[j], mj = nj + dy[j];
			if (0 <= mi&&mi < h && 0 <= mj&&mj < w) {
				int nd;
				if (s[ni][nj] == '.'&&s[mi][mj] == '#')nd = d + 1;
				else nd = d;
				if (nd < dp[mi][mj]) {
					dp[mi][mj] = nd;
					Q.push(PP(nd, P(mi, mj)));
				}
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll x,ans;cin>>x;
  rep(i,1,x+1){
    if((360*i)%x==0){
      ans=(360*i)/x;
      break;
    }
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 3648
n,m=map(int,input().split())
G=[[0]*n for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a][b]=G[b][a]=1

from itertools import permutations
ans=0
for p in permutations([x for x in range(1,n)]):
    ok=True
    t=[0]+list(p)
    for i in range(1,n):
        if G[t[i-1]][t[i]]==0:ok=False
    if ok:ans+=1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N;
  cin >> N;
  vector<int> a(N);
  int cnt = 0, num = 1;
  for(int i = 0; i < N; i++) {
    cin >> a[i];
    if(a[i] == num) {
      num++;
    }
    else {
      cnt++;
    }
  }

  if(cnt == N) cout << -1 << endl;
  else cout << cnt << endl;

  return 0;
}


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

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> v(N);
    for(int i=0; i<N; i++){
        cin >> v[i];
        v[i] -= X;
    }

    int ans = 0;
    for(int i=0; i<N; i++) ans = __gcd(ans, v[i]);
    cout << abs(ans) << endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,x = map(int,input().split())
X = list(map(int,input().split()))
X.append(x)
X.sort()
def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a
    
def lcm(m,n):
    return (m*n)//gcd(m,n)

pro = X[1]-X[0]

for i in range(n):
  pro = gcd(abs(X[i+1]-X[i]),pro)
print(pro)

Measured memory_bytes: 14588
s = map(str, raw_input().split())

stack = []

for op in s:
  if op == '+':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) + int(y)]
  elif op == '-':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) - int(y)]
  elif op == '*':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) * int(y)]
  else:
    stack += [int(op)]
print stack[0]


Measured memory_bytes: 4656
// ~/BAU/ACM-ICPC/Teams/OverflowLimitExceeded/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 100;
const ll MOD = 1e9 + 7;

int n;
vector<pair<int, int> > r, b;
int vc, vis[N], match[N];
vector<vector<int> > g;

bool find_match(int u) {
	if (vis[u] == vc)
		return 0;

	vis[u] = vc;
	for (int i = 0; i<g[u].size(); i++)
		if (match[g[u][i]] == -1 || find_match(match[g[u][i]])) {
			match[g[u][i]] = u;
			return 1;
		}

	return 0;
}

int dfs() {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		++vc;
		if (find_match(i))
			ans++;
	}
	return ans;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif

	scanf("%d", &n);
	for (int i = 0, x, y; i < n; i++) {
		scanf("%d%d", &x, &y);
		r.push_back(make_pair(x, y));
	}
	for (int i = 0, x, y; i < n; i++) {
		scanf("%d%d", &x, &y);
		b.push_back(make_pair(x, y));
	}

	g.resize(n);
	for (int i = 0; i < n; i++) 
		for(int j=0; j<n; j++)
			if (r[i].first < b[j].first && r[i].second < b[j].second) 
				g[i].push_back(j);
				
	memset(match, -1, sizeof match);
	printf("%d\n", dfs());

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long;

const ll p = 1e9 + 7;

int n, l, r;
int used[100001];

long long f[200000 + 1];
long long fi[200000 + 1];
long long bp[40];

long long binpow(long long a, long long b)
{
    bp[0] = 1;
    bp[1] = a;
    for (int i = 2; i < 40; i++)
    {
        bp[i] = (bp[i - 1] * bp[i - 1]) % p;
        //cout << bp[i] << endl;
    }

    int d = 1;
    long long res = 1;

    while (b)
    {
        if (b & 1)
        {
            res = (res * bp[d]) % p;
        }
        d++;
        b = b >> 1;
    }
    return res;
}

void make_ftable(int n)
{
    f[0] = 1;
    fi[0] = 1;
    f[1] = 1;
    fi[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        f[i] = i * f[i - 1] % p;
        fi[i] = binpow(f[i], p - 2) % p;
    }
}

long long C(long long n, long long r)
{
    if (n < 0 || r < 0 || r > n)
    {
        return 0LL;
    }
    if (r > n / 2)
    {
        r = n - r;
    }
    return (f[n] * ((fi[r] * fi[n - r]) % p)) % p;
}

int main()
{
    cin >> n;

    make_ftable(n + 1);

    for (int i = 0; i < 100001; i++)
    {
        used[i] = -1;
    }
    for (int i = 0; i < n + 1; i++)
    {
        int t;
        cin >> t;
        if (used[t] != -1)
        {
            l = used[t];
            r = i;
        }
        used[t] = i;
    }

    ll nC;
    ll mC;
    ll m = l + n - r;

    //cout << "l : " << l << " r : " << r << " m = " << m << endl;

    for (int i = 1; i <= n + 1;i++)
    {
        nC = C(n + 1, i);
        mC = C(m, i - 1);
        cout << (nC - mC + p) % p << endl;
    }

    return 0;
}

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

int main()
{
  int i,n,m,x,y;
  int kari,x_max=-101,y_min=101;
  
  cin>>n>>m>>x>>y;
  
  for(i=0;i<n;i++){
      cin>>kari;
      if(kari>x_max) x_max=kari;
    }

    for(i=0;i<m;i++){
      cin>>kari;
      if(kari<y_min) y_min=kari;

    }

    if( x+1<=y_min && x_max+1<=y &&  x_max+1<=y_min) cout<<"No War"<<endl;
    else cout<<"War"<<endl;

    return 0;
}


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

const int AMAX = 100000;
ll cnt[AMAX+1];

int main(){
  int N;
  ll K;
  cin >> N >> K;
  
  for(int i=0; i<N; i++){
    int A,B;
    cin >> A >> B;
    cnt[A] += B;
  }
  
  for(int ans=1; ans<=AMAX; ans++){
    if(K <= cnt[ans]){
      cout << ans << endl;
      break;
    }
    K -= cnt[ans];
  }
  
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int a[210];
int main()
{
	int n,l,i,j,t;
	while(~scanf("%d%d",&n,&l))
	{
		int sum=0;
		for(i=1;i<=n;i++)
		{
			a[i]=l+i-1;
			sum+=a[i];
		}
		for(i=1;i<=n-1;i++) 
		for(j=i+1;j<=n;j++)
		{
			if(fabs(a[i])>fabs(a[j])){
				t=a[i];a[i]=a[j];a[j]=t; 
			}
		}
		printf("%d\n",sum-a[1]);   
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  string s; cin >> s;
  ll k; cin >> k;

  int sum = 0;
  rep(i,s.size()-1) {
    if (s[i] == s[i+1]) {
      ++sum;
      ++i;
    }
  }

  int f = 0;
  rep(i,s.size()) {
    if (s[i] == s[0]) ++f;
    else break;
  }

  if (f == s.size()) {
    ll length = k * s.size();
    cout << length / 2 << endl;
    return 0;
  }

  int b = 0;
  reverse(all(s));
  rep(i,s.size()) {
    if (s[i] == s[0]) ++b;
    else break;
  }

  ll ans = sum * k;
  if (s.front() == s.back() && f%2 && b%2) ans += k-1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256