akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

vector <int> colors;

void dfs(const vector <vector <pair <int, ll> > >& adj, int now, int col)
{
	colors[now] = col;

	for (const auto& p : adj[now])
	{
		if (colors[p.first] == NG)
		{
			if (p.second % 2 == 0)
			{
				dfs(adj, p.first, col);
			}
			else
			{
				dfs(adj, p.first, 1 - col);
			}
		}
	}
}

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

	vector <vector <pair <int, ll> > > adj(N); // adj[x] = { (y0, w0), (y1, w1), (y2, w2)... }
	colors.resize(N);
	fill(colors.begin(), colors.end(), NG);

	for (int i = 0; i < N-1; ++i)
	{
		int x, y;
		ll w;
		cin >> x >> y >> w;
		x--;
		y--;
		adj[x].push_back(make_pair(y, w));
		adj[y].push_back(make_pair(x, w));
	}

	dfs(adj, 0, 0);

	for (int i = 0; i < N; ++i)
	{
		cout << colors[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 9600
object Main extends App {
    val x = io.StdIn.readInt

    /* TLE case
    var has = false
    for {
        ka <- 0 to x/100
        kb <- 0 to x/101
        kc <- 0 to x/102
        kd <- 0 to x/103
        ke <- 0 to x/104
        kf <- 0 to x/105
        
        if !has
    } if (100*ka+101*kb+102*kc+103*kd+104*ke+105*kf == x) has = true

    if (has) println(1)
    else println(0)
    */

    // val result = (1 to x).exists(c => 100*c <= x && x <= 105*c)
    val result = (1 to x).exists(c => (100*c to 105*c).contains(x))
    if (result) println(1)
    else println(0)
}

Measured memory_bytes: 54736
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N;
ll C;
ll h[200005];

ll dp[200005];
int deq[200005];

ll f(int j, ll x){
  return -2 * h[j] * x + dp[j] + h[j] * h[j] + C;
}

bool check(int f1, int f2, int f3){
  ll a1 = -2 * h[f1], b1 = dp[f1] + h[f1] * h[f1] + C;
  ll a2 = -2 * h[f2], b2 = dp[f2] + h[f2] * h[f2] + C;
  ll a3 = -2 * h[f3], b3 = dp[f3] + h[f3] * h[f3] + C;
  return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2);
}

int main(){
  cin >> N >> C;
  rep(i,N) cin >> h[i];

  int s=0, t=1;
  deq[0] = 0;
  dp[0] = 0;

  REP(i,1,N){
    if(i>0){
      while(s+1<t && t-2>=s && check(deq[t-2], deq[t-1], i-1)) t--;
      deq[t++] = i-1;
    }
    while(s+1<t && deq[s+1]<i && f(deq[s], h[i]) >= f(deq[s+1], h[i])) s++;
    
    dp[i] = h[i] * h[i] + f(deq[s], h[i]);
  }
  
  cout << dp[N-1] << endl;
  
  return 0;
}

Measured memory_bytes: 4096
A, B, C, K = map(int, input().split())

ANS = 0

if A-K <= 0:
    ANS = ANS + A
    num = K - A
    if B - num <= 0:
        Num = num -B
        ANS = ANS - Num 
else:
    ANS = K

print(ANS)

Measured memory_bytes: 9108
s = input()
t = input()
ans = len(s)
for i in range(len(s)):
    if i + len(t) -1 >= len(s):
        break
    dif = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            dif += 1
    ans = min(ans, dif)
print(ans)
        


Measured memory_bytes: 67104
#include<bits/stdc++.h>
using namespace std;
int main()
{
   vector<vector<int> >a;
   int n;
   cin>>n;
   int ne;
   cin>>ne;
   a.resize(n+1);
   for(int i=0;i<ne;i++)
   {
       int e1,e2;
       cin>>e1>>e2;
       a[e1].push_back(e2);
       a[e2].push_back(e1);
   }
   int flag=0;
   vector<int>::iterator p,q;
   for(p=a[1].begin();p!=a[1].end();p++)
   {
        for(q=a[*p].begin();q!=a[*p].end();q++)
        {
            if(*q==n)
            {
                flag=1;
                break;
            }
        }
   }
   if(flag==1)
    cout<<"POSSIBLE";
   else
    cout<<"IMPOSSIBLE";
}


Measured memory_bytes: 12016
#include <stdio.h>

int main(void)
{
	int a;
	int m;
	int h;
	int s;
	
	scanf("%d", &a);
	
	h = a / 3600;
	m = (a - (h * 3600)) / 60;
	s = a - ((h * 3600) + ( m * 60 ));
	
	printf("%d:%d:%d\n", h, m, s);
	
	return (0);
}

Measured memory_bytes: 592
import math
a,b=map(int,input().split())
def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
pa=set(pf(a))
pb=set(pf(b))
res = pa & pb
print(len(res)+1)

Measured memory_bytes: 3064
inpl = lambda: list(map(int,input().split()))
N, M, V, P = inpl()
A = inpl()
A.sort(reverse=True)
s = 0
S = []
for i in range(N):
    s += A[i]
    S.append(s)
S.append(0)
OK = P-1
NG = N
while NG - OK > 1:
    x = (NG+OK)//2
    if A[P-1] > A[x] + M:
        NG = x
    elif P + (N-1-x) >= V:
        OK = x
    else:
        remain = M * (V-P-(N-1-x))
        space = (x-P+1)*(A[x]+M) - (S[x-1] - S[P-2])
        if remain <= space:
            OK = x
        else:
            NG = x
print(OK+1)

Measured memory_bytes: 14964
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  string a,b;
  cin >>a>>b;
  string c=a+b;
  int d=stoi(c);
  for (int i=1; i<=sqrt(d);i++){
  if(i*i==d) {cout<<"Yes"<<endl; return 0;}
}
  cout <<"No"<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()

dp = [None]*(N+1)

dp[0] = 0
for s in S:
  if s == '.':
    dp[0] += 1

for i in range(1, N+1):
  if S[i-1] == '.':
    dp[i] = dp[i-1] - 1
  elif S[i-1] == '#':
    dp[i] = dp[i-1] + 1

print(min(dp))

Measured memory_bytes: 11240
n,y=map(int,input().split())

flag=0
total = 0

for i in range(n+1):
    for j in range(n+1):
        k=n-i-j
        if k<0:
            break

        total=10000*i+5000*j+1000*k
        if total==y:
            print(i,j,k)
            flag=1
            break 
    if flag == 1:
        break
if flag == 0:
    print('-1 -1 -1')

Measured memory_bytes: 9152
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  char c, cl[28] = {'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'};
  cin >> c;
  cout << cl[c - 'a' + 1];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}
bool vis[200005];
vector<int> vec[100005];
int child[100005];
void dfs(int node)
{
    vis[node] = 1;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            child[node] += child[vec[node][i]];
        }
    }
}
void belman(int n, int m, vector<pair<int, pair<int, int>>> vec, int dis[])
{
    for (int i = 0; i <= n + m - 1; i++)
    {
        for (int j = 0; j < vec.size(); j++)
        {
            int u = vec[j].second.first;
            int v = vec[j].second.second;
            int w = vec[j].first;

            if (dis[u] + w < dis[v])
            {
                dis[v] = dis[u] + w;
            }
        }
    }
}
int fun(int a, int b)
{
    if (a > b)
        return 0;
    if (a == b)
        return 1;
    else
    {
        return fun(a + 1, b) + fun(a, b - a);
    }
}
int32_t main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    int n;
    ;
    char str;
    cin >> n; //>> str >> m;
    int sum = 0;

    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int x, y;
        cin >> x >> y;
        cout << sum - arr[x - 1] + y << "\n";
    }

    return 0;
}


Measured memory_bytes: 5964
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for (int i=0;i<n;i++) {
            int d1 = sc.nextInt();
            int d2 = sc.nextInt();
            if (d1==d2) {
                count++;
                if (count==3) {
                    System.out.println("Yes");
                    return;
                }
            } else {
                count=0;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 35976
import math

A, B, H, M = list(map(int, input().split()))

total_minute = H*60 + M
angleH = 2 * math.pi * total_minute / (12*60)
angleM = 2 * math.pi * M / (60)

print((A**2  + B**2 - 2*A*B*math.cos(angleH - angleM))**0.5)


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

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;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

const int INF=1e9;
const double eps=0.0000000001;

int main(){

  string s;
  cin >> s;
  int ans=0;
  char nows=s[0];
  for(int i=1;i<s.size();i++){
    if(nows!=s[i]){
      ans++;
      nows=s[i];
    }
  }

  cout << ans << endl;
  
}


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

int main() {
  int n;
  cin>>n;
  vector<int> b(n-1);
  for (int i=0; i<n-1; i++)
    cin>>b.at(i);
  
  int score = 0;
  score += b.at(0);
  score += b.at(n-2);
  for (int i=0; i<n-2; i++) {
    score += min(b.at(i),b.at(i+1));
  }
  
  cout<<score<<endl;
}

Measured memory_bytes: 256
N, M, K = io.read("*n","*n","*n")
A = {}; for i = 1, N do A[i] = io.read("*n") end
B = {}; for i = 1, M do B[i] = io.read("*n") end

a = {}; a[0] = 0
for i = 1, N do a[i] = a[i-1] + A[i] end

b = {}; b[0] = 0
for i = 1, M do b[i] = b[i-1] + B[i] end

ans = 0
for i = 0, N do
  if a[i] > K then break end
  left = 0
  right = M + 1
  while right - left > 1 do
    cur = (left + right) // 2
    if b[cur] <= K - a[i] then
      left = cur
    else
      right = cur
    end
  end
  ans = math.max(ans, i + left)
end

print(ans)


Measured memory_bytes: 18660
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;

void yes(){
    cout<<"Yes"<<endl;
}

void no(){
    cout<<"No"<<endl;
}

void solve(){
    ll k,n;
    cin>>k>>n;
    vl a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll totDis = 0;
    ll mx = 0;
    for(int i=0;i<n-1;i++){
        totDis+=a[i+1]-a[i];
        if(a[i+1]-a[i]>mx){
            mx = a[i+1]-a[i];
        }
    }
    totDis+=a[0]+k - a[n-1];
    if(a[0]+k - a[n-1]>mx){
        mx = a[0]+k - a[n-1];
    }
    cout<<totDis-mx<<endl;
}

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

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second
using ll = long long;
using P = pair<ll ,ll>;
using Tu = tuple<ll, ll, ll>;
const ll INFLL = 1LL<<60LL;
const ll INF = 1LL<<60LL;
const ll MOD = 1e9+7;



using ld = long double;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

int main(){
  ll L;
  cin >> L;
  L--;
  ll n = 0;
  while((1LL << (n + 1)) - 1 <= L)
    n++;
  ll N = n+1;
  vector<Tu> es;
  for(int i = 0;i<N-1;i++){
    es.push_back(Tu(i, i+1, 0));
    es.push_back(Tu(i, i+1, 1LL << (N-2 - i)));
  }
  ll done = (1LL << n) - 1;
  for(int to=1;to<N;to++){
    ll haba = (1LL << (N - 1 - to)) - 1;
    if(done + 1 + haba <= L){
      es.push_back(Tu(0, to, done+1));
      done += haba + 1;
    }
  }
  cout << N << " " << es.size() << endl;
  for(auto &e : es){
    ll f, t, c;
    tie(f, t, c) = e;
    cout << f + 1 << " " << t + 1 << " " << c << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll da[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>m;
    rep(i,n){
        cin>>a;
        rep(j,a){
            cin>>b;
            da[b]++;
        }
    }
    rep(i,m+1){
        if(da[i]==n)ans++;
    }
    Cout(ans);
    return 0;
}


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

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

    int H, W;
    cin >> H >> W;

    vector<vector<char> > S(H + 2, vector<char>(W + 2));
    vector<vector<int> > x(H + 2, vector<int>(W + 2));

    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            cin >> S[i][j];
            if(S[i][j] == '#') {
                for(int k = i - 1; k <= i + 1; k++) {
                    for(int l = j - 1; l <= j + 1; l++) {
                        x[k][l]++;
                    }
                }
            }
        }
    }

    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            if(S[i][j] == '#') cout << '#';
            else cout << x[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


ll modpow(ll a, ll n){
    if(n==0)return 1;
    if(n%2==0){
      ll t=modpow(a,n/2);
      return (t*t)%MOD;
    }
    return a*modpow(a,n-1)%MOD;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n,k;
  cin >> n >> k;
  vector<ll>vec(k+1);
  
  ll ans=0;
  for(ll i=k;i>=1;i--){
    vec[i]=modpow(k/i,n);
    for(ll j=2*i;j<=k;j+=i){
      vec[i]=(vec[i]-vec[j]+MOD)%MOD;
    }
  }
  for(ll i=1;i<=k;i++){
    ans+=(i*vec[i])%MOD;
    ans%=MOD;
  }
  cout << ans << endl;
  
  
  
}


Measured memory_bytes: 3972
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

c = Array.new(n+1, 0)
a.each {|i| c[i]+=1}
all = c.reduce(0){|res, i| res + i*(i-1)/2}

a.each do |i|
  puts all - c[i]*(c[i]-1)/2 + (c[i]-1)*(c[i]-2)/2
end

Measured memory_bytes: 24580
N = int(input())
S = input()

L = ["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"]
temp = []
ans = ""

for i in range(len(S)):
    su = L.index(S[i])+N
    if su >=26:
        su -= 26
    temp.append(su)
for j in range(len(S)):
    ans += L[int(temp[j])]
    
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

bool check(string A){
	int a[26];
	REP(i,26){
		a[i]=0;
	}
	REP(i,A.size()){
		a[A[i]-'a']++;
		if(a[A[i]-'a']>=2)return false;
	}
	return true;
}

int main(){
	string S;
	cin>>S;
	if(S.size()==26){
		string A=S;
		bool check=false;
		int now=-1;
		int c=-1;
		for(int i=S.size()-1;i>=0;i--){
			for(int j=i+1;j<S.size();j++){
				if(A[i]<A[j]){
					c=i;
					check=true;
					if(now==-1){
						now=j;
					}else{
						if(A[j]<A[now]){
							now=j;
						}
					}
				}
			}
			if(check==true){
				break;
			}
		}
		if(check==false){
			cout<<-1<<endl;
		}else{
			REP(i,c){
				cout<<S[i];
			}
			cout<<S[now]<<endl;
		}
	}else{
		REP(i,26){
			string A=S;
			A.push_back('a'+i);
			//cout<<A<<endl;
			if(check(A)==true){
				cout<<A<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();	
		int [] L = new int [N+1];
		int [] R = new int [N+2];
		
		String color = sc.next(); 
		
		//count of black left of i-th tile
		int left = 0;
		for (int i=0;i<N;i++) {
			if (color.charAt(i) == '#')
				left+=1;
			L[i+1]=left;
			//System.out.println("L="+L[i]+" at i = "+i);
				
		}
		if (N!=1)
			L[N]=L[N-1];
		//System.out.println("L="+L[N]+" at i = "+N);

		//count of white tile right of i-th tile 
		int right = 0;
		for (int i=N;i>0;i--) {
			if (color.charAt(i-1) == '.')
				right+=1;
			R[i]=right;
			//System.out.println("R="+R[i]+" at i = "+i);
		}
		if (N!=1)
			R[0]=R[1];
		
		
		int tile = 100000;
		for (int i=1;i<N+1;i++) {
			//System.out.println("i="+i+" ");
			//System.out.println("L="+L[i-1]);
			//System.out.println("R="+R[i+1]);
			
			tile = Math.min(L[i-1]+R[i+1], tile);
		}
		System.out.print(tile);
	}
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,k; cin>>n>>k;
  ll ans=0;
  ireps(i,k,n+1){
    ll l=i*(i-1)/2;
    ll r=n*(n+1)/2-(n-i+1)*(n-i)/2;
    // cout<<l<<" "<<r<<endl;
    ans+=(r-l+1)%MOD;
    ans=(ans+MOD)%MOD;
  }
  cout<<ans<<endl;
 }

Measured memory_bytes: 3652
//iejr Header files
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <sstream>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <limits.h>
#include <ctime>
#include <cctype>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

//iejr: Type defination
typedef unsigned long long int             ULLN;
typedef long long int                      LLN;
typedef vector<int>                        VI;
typedef vector<vector<int> >               VVI;
typedef vector<string>                     VS;
typedef vector<vector<string> >            VVS;


//iejr: Compile Options
//#define C11_Standard
//
#ifdef C11_Standard
    #include <unordered_set>
    #include <unordered_map>

    #define HASHSET                  unordered_set
    #define HASHMAP                  unordered_map;
#endif // C11_Standard


//iejr: Local Debug
//#define INPUT_REDIRECTION
//#define OUTPUT_REDIRECTION

void dfs( string &s, int pos, LLN sum, LLN &ssum ){
    if( pos == s.length() ){
        ssum += sum;
        return;
    }

    LLN curNum = 0;
    for( int i = pos;i < s.length();++i ){
        curNum *= 10;
        curNum += s[i] - '0';

        dfs( s, i + 1, sum + curNum, ssum );
    }
}

//iejr: Main Function
int main()
{

#ifdef INPUT_REDIRECTION
    freopen( "in.txt", "r", stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    freopen( "out.txt", "w", stdout );
#endif // OUTPUT_REDIRECTION

    string s;
    while( cin >> s ){
        LLN ret = 0;
        dfs( s, 0, 0, ret );

        printf( "%lld\n", ret );
    }

#ifdef INPUT_REDIRECTION
    fclose( stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    fclose( stdout );
#endif // OUTPUT_REDIRECTION

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
a = [int(n) for n in input().split()]

count_a = 0 #+start
count_b = 0 #-start

nowsum = a[0]
if nowsum != 0:
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_a += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]

    count_b += abs(a[0]) + 1
    nowsum = int(a[0] / abs(a[0]) * -1)

    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_b += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n] 

    print(min(count_a, count_b))

else:
    a[0] = 1
    count_a += 1
    nowsum = 1
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_a += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]
    
    a[0] = -1
    count_b += 1
    nowsum = -1
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_b += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]   
    print(min(count_a, count_b))
            



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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s,t;

  int a,b,mx=-19999;
  cin>>a>>b;
  mx=max(mx,a+b);
   mx=max(mx,a-b);
    mx=max(mx,a*b);
    cout<<mx<<endl;

  return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, h, t, s[1009], p[1009], inv[1009], a[100009], b[100009]; pair<int, int> x[100009];
int main() {
	while(scanf("%d%d%d%d", &n, &m, &h, &t), n) {
		for(int i = 0; i < n; i++) scanf("%d", &s[i]), p[i] = i;
		for(int i = 0; i < m; i++) scanf("%d%d", &x[i].second, &x[i].first), x[i].second--, x[i].first--;
		sort(x, x + m);
		for(int i = 0; i < m; i++) {
			swap(p[x[i].second], p[x[i].second + 1]);
			a[i] = p[x[i].second], b[i] = p[x[i].second + 1];
			if(a[i] > b[i]) swap(a[i], b[i]);
		}
		int sum = 0;
		for(int i = 0; i < n; i++) {
			if(p[i] < t) sum += s[i];
			inv[p[i]] = i;
		}
		int ret = sum;
		for(int i = 0; i < m; i++) {
			if(a[i] < t && b[i] >= t) {
				ret = min(ret, sum - s[inv[a[i]]]+ s[inv[b[i]]]);
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 4656
# N本の竹、必要な3本の竹の長さはABC
N, A, B, C = map(int, input().split())
# 現在持っているそれぞれの竹の長さ（最大8本）
l = [int(input()) for i in range(N)]
INF = 10**9


def dfs(cur, a, b, c):
    # 竹の本数が全ての竹の場合だけ求める
    if cur == N:
        # min(a, b, c) > 0 は最低でも竹を作るには1本以上の竹が必要なため
        if min(a, b, c) > 0:
            # 現在（合体後）のabcそれぞれの竹の長さからABCにするの必要なコストを求める
            # 最初の再帰呼び出し時は合体をしていないので10*ABC3種分の30は引く
            return abs(a-A)+abs(b-B)+abs(c-C)-30
        else:
            return INF

    # 4のn乗の全探索をする
    ret0 = dfs(cur + 1, a, b, c)
    # 竹の追加＝合体なので+10している
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
n=int(input())
ans=0
dn=n
g={}
d=2
while d*d<=dn:
    if dn%d==0:
        if not g.get(d):g[d]=0
        while dn%d==0:dn//=d;g[d]+=1
    d+=1
if dn>1:g[dn]=1
for v in g:
    i=g[v]
    cnt=1
    while cnt<=i:i-=cnt;cnt+=1;ans+=1
print(ans)

Measured memory_bytes: 9200
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

typedef pair<int, int> P;

int n;
vector<int> A, B;
vector<P> vec;

int main() {
  cin >> n;
  vec.assign(n, P());
  rep(i, n) { cin >> vec[i].second >> vec[i].first; }
  sort(vec.begin(), vec.end());

  cout << endl;
  bool can = true;
  int t = 0;
  rep(i, n) {
    int a = vec[i].second;
    int b = vec[i].first;
    t += a;
    if (t > b) {
      can = false;
      break;
    }
  }
  string ans = can ? "Yes" : "No";
  cout << ans << endl;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
constexpr int MOD = 1e9 + 7;
//} END

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

  int n, k, cnt = 1, to;
  cin >> n >> k;
  vector<int> a(n);
  arep(i, a) cin >> i;

  vector<int> ans, z(n + 1, -1);

  while (z[cnt] == -1) {
    z[cnt] = ans.size();
    ans.push_back(cnt);
    cnt = a[cnt - 1];
  }

  to = ans.size() - z[cnt];
  cnt = z[cnt];

  if (k < cnt)
    cout << ans[k] << '\n';
  else {
    k -= cnt;
    k %= to;
    cout << ans[cnt + k] << '\n';
  }
  return 0;
}

Measured memory_bytes: 8436
#include <stdio.h>

int	main(void){
	int	i = 0;
	char	word[1003] = {};

	scanf("%s", word);
	
	while (word[i] != '\0'){
		i++;
	}

	if (word[i - 1] == 's'){
		word[i] = 'e';
		word[i + 1] = 's';
	}else{
		word[i] = 's';
	}

	printf("%s\n", word);
	return (0);
}


Measured memory_bytes: 1664
from collections import Counter
from bisect import bisect_left
import sys
input = sys.stdin.readline


def main():
    _ = int(input())
    L = list(map(int, input().split()))
    counter = Counter(L)
    L = list(set(L))
    L.sort()
    n = len(L)
    
    cumsum = []
    total = 0
    for l in L:
        total += counter[l]
        cumsum.append(total)


    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            a, b = L[i], L[j]
            limit = a + b
            k = bisect_left(L, limit, lo=j+1)
            pattern = counter[a] * counter[b] * (cumsum[k-1] - cumsum[j])
            ans += pattern

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9480
#include <stdio.h>
using namespace std;
int max(int a,int b) {return (a)>(b)?(a):(b);}
int min(int a,int b) {return (a)<(b)?(a):(b);}
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	printf("%d\n",max(min(d,b)-max(a,c),0));
	return 0;
}

Measured memory_bytes: 128
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%3==0 || B%3==0 || (A+B)%3==0){
            System.out.println("Possible");
        }
        else{
            System.out.println("Impossible");
        }
    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
//static const int INFTY = (1<<20);


//ABC153_c
int main() {
	int N, K;
	cin >> N >> K;

	vector<int64_t> vec(N);
	rep(i, N) {
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end(), greater<int64_t>());

	int64_t ans = 0;
	if (N > K) {
		for (int i=K; i<N; i++) {
			ans += vec.at(i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
(n,m),*s,p=[list(map(int,t.split()))for t in open(0)]
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n*m):j,k=j//m,j%m;c[k]+=i>>j&(j+1in s[k][1:])
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

Measured memory_bytes: 3060
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int n;
struct guy {
	int m, l;
	vi v;
	guy() {
		v.assign(16, 0);
	}
	
};
ll vtoi(vl v) {
	ll ret = 0;
	ll p = 1;
	REP(i, v.size()) {
		ret += p*v[i];
		p *= 2;
	}
	return ret;
}
vl itov(ll i) {
	vl ret(16);
	REP(j, 16) {
		ret[j] = i % 2;
		i /= 2;
	}
	return ret;
}
ll dfs(vector<guy> &guys, vl &dp,int s) {
	if (dp[s] != -1)return dp[s];
	vl v = itov(s);
	ll ret = 0;
	REP(i, n) {
		vl tmp = v;
		REP(j, 16)tmp[j] += guys[i].v[j];
		if (*max_element(ALL(tmp)) <= 1) {
			ret = max(ret, guys[i].l + dfs(guys, dp, vtoi(tmp)));
		}
	}
	return dp[s] = ret;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1)  {
		
		cin >> n;
		if (!n)break;
		vector<guy> guys(n);
		REP(i, n) {
			cin >> guys[i].m >> guys[i].l;
			REP(j, guys[i].m) {
				int s, t;
				cin >> s >> t;
				s -= 6; t -= 6;
				FOR(k, s, t)guys[i].v[k]++;
			}
			/*if (*max_element(ALL(guys[i].v)) > 1) {
				guys[i].l = 0;
				REP(j, 16) {
					guys[i].v[j] = 0;
				}
			}*/

		}
		vl dp(1 << 16, -1);
		vi used(16, 0);
		cout << dfs(guys, dp, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
int cnt[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (n--) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  sort(cnt, cnt + N, greater<int>());
  int ret = 0;
  for (int i = m; i < N; ++i) {
    ret += cnt[i];
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    vector<int> a(n + 1);
    ll s = 0;
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
        s += a[i];
    }

    vector<ll> b(n + 1);
    ll t = 1;
    for (int i = 0; i <= n; i++) {
        t -= a[i];
        s -= a[i];
        if (t < 0) {
            cout << -1 << endl;
            exit(0);
        }
        b[i] = t = min(t, s);
        t *= 2;
    }

    ll r = 0;
    for (int i = n; i >= 0; i--) {
        ll t = a[i] + b[i];
        r += t;
        if (i == 0) break;
        if (t < b[i - 1]) b[i - 1] = t;
    }

    cout << r << endl;

    return 0;
}

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

int main() {
    
    string s;
    getline(cin,s);
    
    int len = s.length();
    int cnt=0;
    
    if (len%2 != 0)
    {
        int mid = len/2;
        int i = mid-1, j = mid+1;
        
        while (i>=0 && j<=len-1)
        {
            if (s[i] != s[j])
                cnt++;
            i--;
            j++;
        }
        
    }
    else
    {
        int mid = len/2;
        int i = mid-1, j = mid;
        
        while (i>=0 && j<=len-1)
        {
            if (s[i] != s[j])
                cnt++;
            i--;
            j++;
        }
    }
    
    cout << cnt << endl;

}

Measured memory_bytes: 256
N = int(input())
cnt = 0
answer = 1
answer_cnt = 0

for i in range(1, N + 1):
    cnt = 0
    m = i
    while m & 1 == 0:
        m >>= 1
        cnt += 1
    if cnt > answer_cnt:
        answer_cnt = cnt
        answer = i
print(answer)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

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

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

const int INF = 1e9;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------

int n;
ll x, xs;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> x >> xs;
  ll ans = abs(xs - x);
  REP(i, n-1) {
    cin >> x;
    ans = __gcd(ans, abs(xs - x));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
a = input().split()
a_n = [int(s) for s in a]

dict = {}
for i in range(N):
    if a_n[i] in dict:
        dict[a_n[i]] += 1
    else:
        dict[a_n[i]] = 1

cnt = 0
for i in dict:
    if dict[i] > i:
        cnt += dict[i] - i
    elif dict[i] < i:
        cnt += dict[i]
print(cnt)

Measured memory_bytes: 24440
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int n; cin >> n;
	long long p[114514], x; cin >> x;
	for (int i = 0; i < n; i++)
		cin >> p[i];
	sort(p, p + n);
	int ans = 0;
	for (; ans < n; ans++) {
		if (p[ans] <= x) { x -= p[ans]; }
		else {
			cout << ans << endl; return 0;
		}
	}
	cout << (!x ? ans : ans - 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
//	if(n==1)
//	{
//		cout << "1";
//		return 0;
//	}
//	if(n==2)
//	{
//		cout << "8";
//		return 0;
//	}
	cout << n*n*n;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX (ll)(3e3 + 7)
#define INF (ll)(4e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;

int dp[MAX][MAX];
int mult (int a, int b) {
	return (a * 1LL * b) % MOD;
}

int add (int a, int b) {
	return (a + b) % MOD;
}

int pw (int a, int b) {
	int r = 1;
	while (b) {
		if (b & 1) {
			r = mult  (r, a);
		}
		b >>= 1;
		a = mult (a, a);
	}	
	return r;
}

int main () {
	int n, s;
	cin >> n >> s;
	int ar[n];
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
	}
	dp[0][0] = pw (2, n);
	int div = pw (2, MOD - 2);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s; j++) {
			dp[i + 1][j] = add (dp[i + 1][j], dp[i][j]);
			if (ar[i] + j <= s) {
				dp[i + 1][ar[i] + j] = add (dp[i + 1][ar[i] + j], mult (dp[i][j], div))	;
			}
		}
	}
	cout << dp[n][s] << "\n";
}
		


Measured memory_bytes: 38836
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		long k = 0;
		for(int i = 0; i < N; i++) {
			if(i % 2 == 0) k += A[N - i - 1];
			else k -= A[N - i - 1];
		}
		k /= 2;
		long X = k;
		System.out.print(2 * X);
		for(int i = 1; i < N; i++) {
			X = A[i - 1] - X;
			System.out.print(" " + 2 * X);
		}
	}
}


Measured memory_bytes: 66604
N=[int(x) for x in input().split()]
if not N[2]%N[1]==0:
   c=N[2]//N[1]+1
else:
    c=N[2]//N[1]
if not N[0]%N[3]==0:
   d=N[0]//N[3]+1
else:
    d=N[0]//N[3]
if d>=c:
    print("Yes")
else:
    print("No")

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

int main() {
	int n,a;
	bool ans;
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>a;
		if(a%2==0) {
			if(a%5==0 || a%3==0) ans=true;
			else {
				ans=false;
				break;
			}
		}
	}
	(ans) ? printf("APPROVED\n") : printf("DENIED\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int i,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0,c10=0,c11=0,c12=0,c13=0,c14=0,c15=0,c16=0,c17=0,c18=0,c19=0,c20=0,c21=0,c22=0,c23=0,c24=0,c25=0,c26=0;
    for(i=0;i<s.length();i++){
        if(s[i]=='a'){
            c1++;
        }
        else if(s[i]=='b'){
            c2++;
        }
        else if(s[i]=='c'){
            c3++;
        }
         else if(s[i]=='d'){
            c4++;
        }
         else if(s[i]=='e'){
            c5++;
        }
         else if(s[i]=='f'){
            c6++;
        }
         else if(s[i]=='g'){
            c7++;
        }
         else if(s[i]=='h'){
            c8++;
        }
         else if(s[i]=='i'){
            c9++;
        }
         else if(s[i]=='j'){
            c10++;
        }
         else if(s[i]=='k'){
            c11++;
        }
         else if(s[i]=='l'){
            c12++;
        }
         else if(s[i]=='m'){
            c13++;
        }
         else if(s[i]=='n'){
            c14++;
        }
         else if(s[i]=='o'){
            c15++;
        }
         else if(s[i]=='p'){
            c16++;
        }
         else if(s[i]=='q'){
            c17++;
        }
         else if(s[i]=='r'){
            c18++;
        }
         else if(s[i]=='s'){
            c19++;
        }
         else if(s[i]=='t'){
            c20++;
        }
         else if(s[i]=='u'){
            c21++;
        }
         else if(s[i]=='v'){
            c22++;
        }
         else if(s[i]=='w'){
            c23++;
        }
         else if(s[i]=='x'){
            c24++;
        }
         else if(s[i]=='y'){
            c25++;
        }
         else if(s[i]=='z'){
            c26++;
        }
    }
    if(c1<=1 && c2<=1 && c3<=1 && c4<=1 && c5<=1 && c6<=1 && c7<=1 && c8<=1 && c9<=1 && c10<=1 && c11<=1 && c12<=1 && c13<=1 && c14<=1 && c15<=1 && c16<=1 && c17<=1 && c18<=1 && c19<=1 && c20<=1 && c21<=1 && c22<=1 && c23<=1 && c24<=1 && c25<=1 && c26<=1){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	s := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}

	ans := 0
	hb := 0
	ta := 0
	hbta := 0
	for _, v := range s {
		c := strings.Count(v, "AB")
		if c > 0 {
			strings.Replace(v, "AB", "", c)
			ans += c
		}
		if strings.HasPrefix(v, "B") && strings.HasSuffix(v, "A") {
			hbta++
			continue
		}
		if strings.HasPrefix(v, "B") {
			hb++
		}
		if strings.HasSuffix(v, "A") {
			ta++
		}
	}
	if hbta == 0 {
		if hb < ta {
			ans += hb
		} else {
			ans += ta
		}
	} else {
		if hb+ta == 0 {
			ans += hbta - 1
		} else {
			ans += hbta
			if hb < ta {
				ans += hb
			} else {
				ans += ta
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1408
from sys import stdin

input = stdin.buffer.readline

n = int(input())
v = [[] for _ in range(n+1)]
edge = [0] * -~n

ans = 0


def dfs(c,fa,x):
    global ans
    color = 1
    for to, eg in v[x]:
        if to == fa:
            continue
        if color == c:
            color += 1
        edge[eg] = color
        ans = max(ans, color)
        dfs(color, x, to)
        color += 1


def bfs(x):
    q = [[0,0,x]]
    ans = 0
    while len(q):
        c, fa, now = q.pop()
        color = 1
        for to, eg in v[now]:
            if to == fa:
                continue
            if color == c:
                color += 1
            edge[eg] = color
            q.append([color, now, to])
            ans = max(ans, color)
            color += 1
    return ans


for i in range(n - 1):
    a, b = map(int, input().split())
    v[a].append([b, i])
    v[b].append([a, i])

print(bfs(1))
for i in range(n-1):
    print(edge[i])






Measured memory_bytes: 78752
#include <stdio.h>

#define N 20
#define Q 200
#define ele 2000

int solve(int i,int m);

int A[N];
int n;

int main(){
  int q,i;
  int m[Q];

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

  scanf("%d",&q);

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

   for(i=0;i<q;i++){
     if(solve(0,m[i]) == 1){
       printf("yes\n");
     }
     else{
       printf("no\n");
     }
  }
  
  return 0;
}

int solve(int i,int m){
  int res;
  
  if(m == 0)
    return 1;
  if(i >= n)
    return 0;

  res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}



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

using namespace std;
using ll = long long;

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

	map<string, int> ans;
	ans["SUN"] = 7;
	ans["MON"] = 6;
	ans["TUE"] = 5;
	ans["WED"] = 4;
	ans["THU"] = 3;
	ans["FRI"] = 2;
	ans["SAT"] = 1;

	string s;
	cin >> s;

	cout << ans[s];
}

Measured memory_bytes: 3628
x = input()
y = len(x)

def main(x,y):
  
  for i,st in enumerate(x):
    if (i+1)%2 == 0:
      if st == 'R':
        return "No"
    else:
      if st == 'L':
         return "No"
  return "Yes"

res = main(x,y)
print(res)

Measured memory_bytes: 2940