akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define DUMP(x) cerr<<#x<<":="<<(x)<<endl
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<" "<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":"\n");return os;}
//------------------------------------------------------------------------------

signed main() {
    int n;
    ll t,a;
    cin>>n;
    ll T=1,A=1;
    REP(i,n) {
        cin>>t>>a;
        if(T>A) {
            while(T%t!=0) T++;
            ll s=T/t;
            if(A>s*a) {
                while(A%a!=0) A++;
                ll s=A/a;
                T=s*t;
            }
            else A=s*a;
        }
        else {
            while(A%a!=0) A++;
            ll s=A/a;
            if(T>s*t) {
                while(T%t!=0) T++;
                ll s=T/t;
                A=s*a;
            }
            else T=s*t;
        }
    }
    cout<<T+A<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
lis = list(map(int, input().split())) 
count = 0
boolean = True
while boolean:
    for i in range(N):
        if lis[i] % 2 == 1:
            boolean = False
            break
        else:
            lis[i] /= 2

    if boolean:
        count +=1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int n; cin >> n;
  vi p(n);
  rep(i, n) cin >> p[i];
  vi lmin(n);
  lmin[0] = p[0];
  rep(i,n-1) lmin[i+1] = min(p[i+1],lmin[i]);
  int ans = 0;
  rep(i,n) {
    //printf("%d %d\n", p[i], lmin[i]);
    if(p[i] == lmin[i]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        ArrayDeque<String> deq = new ArrayDeque<>();
        for (int i = 0; i < str.length(); i++) {
            String s = String.valueOf(str.charAt(i));
            deq.offerLast(s);
        }
        int q = sc.nextInt();
        
        int reverse = 0;
        while (q-- > 0) {
            int type = sc.nextInt();
            if (type == 1) {
                reverse ^= 1;
            } else {
                int index = sc.nextInt()-1;
                String s = sc.next();
                if (reverse == 1) {
                    index ^= 1;
                }
                
                if (index == 0) {
                    deq.offerFirst(s);
                } else {
                    deq.offerLast(s);
                }
            }
        }
        
        if (reverse == 0) {
            while (!deq.isEmpty()) {
                System.out.print(deq.pollFirst());
            }
        } else {
            while (!deq.isEmpty()) {
                System.out.print(deq.pollLast());
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 82504
#include <iostream>
#include <iomanip>
#include <cmath>
int main()
{
  int n;
  std::cin >> n;
  while (n--) {
    double x1, y1, x2, y2, x3, y3, px, py, r;
    std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double c = 2.0 * ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));
    px = ((y3 - y1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) +
          (y1 - y2) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)) / c;
    py = ((x1 - x3) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) +
          (x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)) / c;
    r = std::sqrt(std::pow(x1 - px, 2) + std::pow(y1 - py, 2));
    std::cout << std::fixed << std::setprecision(3) << px << " " <<
      py << " " << r << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1292
def d_div_game():
    def prime_factorization_dict(n):
        """n を素因数分解したときの素数とその指数の辞書"""
        from collections import defaultdict
        if n == 1:
            return {2: 0}  # 1 は素数の 0 乗の積とみなす
        i, table = 2, defaultdict(int)
        while i**2 <= n:
            while n % i == 0:
                table[i] += 1
                n //= i
            i += 1
        if n > 1:
            table[n] = 1
        return table

    def sub_calc(n):
        """t = 1 + ... + e <= n となる最大の e を求め、そのときの項数を返す"""
        t, e = 0, 1
        while True:
            t += e
            if t > n:
                return e - 1
            e += 1

    return sum(sub_calc(v) for v in prime_factorization_dict(int(input())).values())

print(d_div_game())

Measured memory_bytes: 9404
#include<iostream>
#include<vector>
#include<string>
using namespace std;

//input
int H, W;
vector<string> Grid;


int dp[1010][1010] = {0};

int MOD = 1000000000 + 7;


int main() {
    cin >> H >> W;

    for (int i = 0; i < H; ++i) {
        string s; cin >> s;
        Grid.push_back(s);
    }
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (Grid[i][j] == '.' && i - 1 >= 0) {
                dp[i][j] += dp[i-1][j];
                dp[i][j] %= MOD;
            }

            if (Grid[i][j] == '.' && j - 1 >= 0) {
                dp[i][j] += dp[i][j-1];
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 5248
n = int(input())

pairs = []
i = 1
while (i * i) <= n:
    if 0 == n % i:
        pairs.append([i, int(n / i)])
    i += 1

ans = 10000000000
for pair in pairs:
    a = len(str(pair[0]))
    b = len(str(pair[1]))
    ans = min(ans, a if a > b else b)
print(ans)


Measured memory_bytes: 3188
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
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 Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    int N; cin >> N;
    ll a[N]; rep(i,N) cin >> a[i];

    ll sum = 0;
    int m = 0;
    int z = 0;
    rep(i,N) {
        sum += abs(a[i]);
        if (a[i] < 0) ++m;
        if (a[i] == 0) ++z;
    }
    ll ans = -sum;
    rep(i,N) {
        ll tmp = sum - abs(a[i]);
        int z_tmp = z;
        if (a[i] == 0) --z;
        if (z > 0) {
            tmp += abs(a[i]);
        } else {
            int m_tmp = m;
            if (a[i] < 0) --m_tmp;
            if (m_tmp % 2 == 0) {
                tmp += a[i];
            } else {
                tmp -= a[i];
            }
        }
        ans = max(ans, tmp);
    }
    out(ans);

    return 0;
}





Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};
int dyy[]={1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1};
int dxx[]={0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1};

int xs,ys,xg,yg,N;
vector<pair<int,double>>g[1010];
vector<pair<pint,int>>v;
double dist[1010];

signed main() {
    IOS();
    cin>>xs>>ys>>xg>>yg>>N;
    vector<pair<pint,int>>v(N+2);
    v[0]={{xs,ys},0};
    v[N+1]={pint(xg,yg),0};
    rep(i,1,N+1){
        int a,b,c;
        cin>>a>>b>>c;
        v[i]={pint(a,b),c};
    }
    rep(i,0,N+2){
        rep(j,i+1,N+2){
            if(i==j)continue;
            double d=max(hypot(v[i].fi.fi-v[j].fi.fi,v[i].fi.se-v[j].fi.se)-v[i].se-v[j].se,0.0);
            g[i].pb({j,d});
            g[j].pb({i,d});
        }
    }
    
    priority_queue<pair<double,int>>que;
    que.push({0,0});
    rep(i,0,N+2)dist[i]=INF;
    dist[0]=0;
    while(!que.empty()){
        int now=que.top().se;
        que.pop();
        for(auto e:g[now]){
            if(dist[e.fi]>dist[now]+e.se){
                dist[e.fi]=dist[now]+e.se;
                que.push({-dist[e.fi],e.fi});
            }
        }
    }
    
    printf("%.15lf",dist[N+1]);
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	int a=0,b=0,c=0,d=0;
	for(int i=0;i<s.size();i++)
	{
		if(s.at(i)=='S')
		{
			a++;
		}
		if(s.at(i)=='N')
		{
			b++;
		}
		if(s.at(i)=='E')
		{
			c++;
		}
		if(s.at(i)=='W')
		{
			d++;
		}
	}
	string k = "Yes";
	if((a>0 && b==0)||(b>0&&a==0))
	{
		k = "No";
	}
	if((c>0 && d==0)||(d>0&&c==0))
	{
		k = "No";
	}
    cout << k << endl;
	return 0;
}

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

double CalcDist(double x1, double x2, double y1, double y2) {
	double xd = x1 - x2;
	double yd = y1 - y2;
	return sqrt(xd * xd + yd * yd);
}

int Factorial(int n) {
	int ans = 1;
	for (int i = 2; i <= n; i++) ans *= i;
	return ans;
}

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

	double MeanDist=0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) continue;
			double Dist = CalcDist(X[i], X[j], Y[i], Y[j]);
			MeanDist += Dist * Factorial(N - 1);
		}
	}
	MeanDist /= Factorial(N);
	printf("%f\n", MeanDist);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int l[10],r[10]={-1};
    int i,j,k,c[10],n=0;
    for(i=0;i<10;i++){
        c[i]=11;
    }
    for(i=0;i<10;i++){
        scanf("%d",&l[i]);
    }
    for(j=0;j<10;j++){
        for(i=0;i<10;i++){
            for(k=0;k<10;k++){
                if(c[k]==i){
                    n=1;
                }
            }
            if(!(n==1)){
                if(l[i]>=r[j]){
                    r[j]=l[i];
                    c[j]=i;
                }
            }
            n=0;
        }
    }
    for(i=0;i<3;i++){
        printf("%d\n",r[i]);
    }
    return 0;
}

Measured memory_bytes: 600
N, Y = map(int, input().split())

def main(Y):
    for i in range(Y//5000+1):
        b = i
        c = Y//1000 - 5*i
        if b//2 + b%2 + c <= N <= b + c:
            for j in range(b//2+1):
                if j + (b - 2*j) + c == N:
                    return (j, b - 2*j, c)
    return (-1, -1, -1)

result = main(Y)
print(' '.join(map(str, result)))

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

bool check(ll x){
  ll cnt=0;
  while(x/k)x=x-(x+k-1)/k,cnt++;
  cnt+=x;
  return cnt >= n;
}

ll search(){
  if( n <= k) return n-1;

  ll L = n,M,R = (1e18)+10;
  while(L<R){
    M = (L+R)/2;
    if(check(M)) R = M;
    else L = M+1;
  }
  return L - 1;
}

int main(){
  cin>>n>>k;
  cout<<search()<<endl;
  return 0;
}

Measured memory_bytes: 3112
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <queue>
#include <string.h>

const int MOD = 1000000007;

int main(int argc, char *argv[])
{
	int n,k;

	cin>>n>>k;

	ll ret=0;
	for (ll i=k;i<=n+1;i++)
	{
		ll a=i*(i-1)/2;
		ll b=i*(n+n-i+1)/2;

		cerr<<i<<" "<<a<<" "<<b<<endl;
		ret=(ret+(b-a+1))%MOD;
	}
	cout<<ret<<endl;

	return 0;
}


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

int main(){
  map<int, int> a;
  for(int i = 0; i < 3; i++){
    int t; cin >> t;
    a[t]++;
  }
  if(a[5] == 2 && a[7] == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  float max_density=0;
  ll memo_x=100*a;
  ll memo_y=0;
  REP(ia, 31){
    REP(ib, 31){
      REP(ic, 101){
        REP(id, 101){
          ll sum=100*a*ia+100*b*ib+c*ic+d*id;
          ll sugar=c*ic+d*id;
          if(sum==0)break;
          if(sum>f)break;
          if(sugar>e*(a*ia+b*ib))break;
          float density=(float)100*sugar/sum;
          if(density>max_density){
            max_density=density;
            memo_x=sum;
            memo_y=sugar;
          }
        }
      }
    }
  }
  cout<<memo_x<<" "<<memo_y<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//const int INF = 100100100;
const int INF = INT_MAX;
int dis(vector<int> &h, int index1, int index2){//h.at(index1) と h.at(index2)の距離
  return abs(h.at(index1) - h.at(index2));
}

int cost_i(vector<int> &h, vector<int> &cost, int index, int K){//DPでdp[i]を求める関数
  for(int i=1; i<=K; i++){
    if(index - i >= 0){//out of rangeを防ぐ
      cost.at(index) = min(cost.at(index), cost.at(index-i)+dis(h, index-i, index));
      //if(cost.at(index) == 0) cout << "0になっている! なぜだ!!!" << "i :" << i << endl;
      //cout << "index: " << index << " i: " << i << " cost.at(index): " << cost.at(index) << endl;
    }
  }
  return  cost.at(index);//0になっている!なぜだ!!!の原因はこの行を書いてなかったら、でした．
}

void dp(vector<int> &h, vector<int> &cost, int N, int K){//cost_iとは違いdpを全部計算する関数
  for(int index=1; index<=N-1; index++){
    for(int j=K; j>=0; j--){
      if(index-j < 0) continue;
      cost.at(index) = min(cost.at(index), cost.at(index-j)+dis(h, index-j, index));      
    }
  } 
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N), cost(N,INF);
  for(int i=0; i<N; i++) cin >> h.at(i);
  
  cost.at(0) = 0;//初期化
  
  //cost.at(1) = cost_i(h, cost, 1, K);
  //cost.at(2) = cost_i(h, cost, 2, K);
  
  //解1
  //for(int index=1; index<=N-1; index++) cost.at(index) = cost_i(h, cost, index, K);//dp[1]から順に求めるforループ
  
  //解2
  dp(h, cost, N, K);
  
  cout << cost.at(N-1) << endl;
  
  /*
  //////////////////////答えがちゃんと出ないので， 以下　関数の確認してみる
  for(int i=0; i<N-1; i++) cout << dis(h, i, i+1) << " ";
  cout << endl;
  cout << "dp:: " << endl;
  for(int i=0; i<N; i++) cout << cost.at(i) << " ";
  cout << endl;
  
  cout << "dis(h, 0, 2) : " << dis(h, 0, 2) << endl;
  cout << "dis(h, 1, 3) : " << dis(h, 1, 3) << endl;
  //cost.at(index) = min(cost.at(index), cost.at(index-i)+dis(h, index-i, index));
  cost.at(1) = min(cost.at(1), cost.at(1-1)+dis(h, 1-1, 1));//index=1, i=1
  cout<< min(cost.at(1), cost.at(1-1)+dis(h, 1-1, 1)) << endl;
  cost.at(2) = min(cost.at(2), cost.at(2-1)+dis(h, 2-1, 2));//index=2, i=1
  cout <<  min(cost.at(2), cost.at(2-1)+dis(h, 2-1, 2)) << endl;
  cost.at(2) = min(cost.at(2), cost.at(2-2)+dis(h, 2-2, 2));//index=2, i=2
  cout << min(cost.at(2), cost.at(2-2)+dis(h, 2-2, 2)) << endl;
  cout << "INF : " << INF << endl;
  cout << " cost.at(1) :" << cost.at(1) << endl;
  cout << " cost.at(2) :" << cost.at(2) << endl;
  
  cout << " cost_i(h, cost, 1, K) :" << cost_i(h, cost, 1, K) << endl;
  cout << " cost_i(h, cost, 2, K) :" << cost_i(h, cost, 2, K) << endl;
  */
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first fi;
#define second se;
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> d, e(m);
    vector<bool> f(n + 1, true);
    rep(i, 0, m){
        cin >> e[i];
    }
    repb(i, m - 1, 0){
        if(f[e[i]]){
            d.push_back(e[i]);
            f[e[i]] = false;
        }
    }
    rep(i, 0, d.size()){
        cout << d[i] << endl;
    }
    rep(i, 1, n + 1){
        if(f[i]) cout << i << endl;
    }
}

Measured memory_bytes: 4644
#include <bits/stdc++.h>
#include <atcoder/dsu>

using namespace std;
using namespace atcoder;

int n, q;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &q);
    dsu d(n);
    while (q--) {
        int tp, u, v;
        scanf("%d%d%d", &tp, &u, &v);
        if (!tp) {
            d.merge(u, v);
        } else {
            printf("%d\n", d.same(u, v));
        }
    }
    return 0;
}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL ans,a,b;
int main(){
	cin >> a >> b,ans = a,a -= b;
	while (a && b){
		if (a > b) swap(a,b);
		if (b % a == 0) ans += ((b/a)*2-1) * a,b %= a;
		else ans += (b/a) * a * 2,b %= a;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3612
import math


def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


def summ(a, b):
    return int((b*(b+1) - a*(a-1)) // 2)


N, K = list(map(int, input().split()))

ans = 0
M = N + 1 - K

MOD = 10**9+7

for m in range(M + 1):
    #print(summ(N-(m+K-1), N) - summ(0, m+K-1) + 1)
    ans += (summ(N-(m+K-1), N) - summ(0, m+K-1) + 1) % MOD

#print(summ(1, 3))
print(ans % MOD)


Measured memory_bytes: 9204
l,r = map(int,input().split())
mod = 2019
ans = 2018
if r-l>=2018:
    print(0)
else:
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans = min(ans,(i*j)%mod)
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  string s;
  cin >> s;
  int n=s.size();
  int k;
  cin >> k;
  ll dp[n][k+1][2];
  rep(i,n)rep(j,k+1)rep(l,2) dp[i][j][l]=0;
  reverse(s.begin(),s.end());
  for(int i =n-1;i>=0;i--){
    //i==n-1のとき
    if(i==n-1){
      int cn = s[i] -'0';
      //      cout << cn << endl;
      dp[i][0][1] = 1;
      dp[i][1][0] = 1;
      dp[i][1][1] = cn-1;
      continue;
    }
       
    //1->1
    rep(ki,k+1){
      dp[i][ki][1] += dp[i+1][ki][1];//0       
    }
    rep(ki,k){
      dp[i][ki+1][1] += dp[i+1][ki][1]*9;//1-9
      //      cout << dp[i+1][ki][1]*9 << endl;
      //      cout << dp[i][ki+1][1] << endl;
    }
    int cn = s[i] -'0';
    //0->1
    if(cn!=0){
      //0
      rep(ki,k+1){
	dp[i][ki][1] += dp[i+1][ki][0];
      }
      rep1(j,cn-1){
	rep(ki,k){
	  dp[i][ki+1][1] += dp[i+1][ki][0];
	}	      
      }
    }
    //0->0
    if(cn==0){
      rep(ki,k+1){
	dp[i][ki][0] += dp[i+1][ki][0];
      }
    }    
    else{
      rep(ki,k){
	dp[i][ki+1][0] += dp[i+1][ki][0];
      }
    }
  }
      //  cout << dp[0][k][0] << endl;
  cout << dp[0][k][1] + dp[0][k][0] << endl;

  
  return 0;
    

}


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

int main() {
    int h, w, a[30][30], ans=IINF;
    cin >> h >> w;
    REP(i,h)REP(j,w) cin >> a[i][j];
    REP(m,h){
        REP(n,w){
            int tmp=0;
            REP(i,h){
                REP(j,w){
                    tmp += min(abs(i-m),abs(j-n))*a[i][j];
                }
            }
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3104
while True:
    n = int(input())
    if n == 0:
        break
    t = []
    for i in range(n):
        t.append(list(map(str, input().split())))
    
    l = [0]*(10**6)
    for i in range(n):
        date = []
        for j in range(2):
            date.append(list(t[i][j]))

        date1 = 3600*(int(date[0][0])*10+int(date[0][1])) + 60*(int(date[0][3])*10+int(date[0][4])) + (int(date[0][6])*10+int(date[0][7]))
        date2 = 3600*(int(date[1][0])*10+int(date[1][1])) + 60*(int(date[1][3])*10+int(date[1][4])) + (int(date[1][6])*10+int(date[1][7]))

        l[date1] += 1
        l[date2] -= 1
    
    for i in range(len(l)-1):
        l[i+1] += l[i]

    print(max(l))


Measured memory_bytes: 33160
#include <stdio.h>
#include <stdlib.h>
int main(void){
  int *ip;
  int *emp;
  int num,i;
  scanf("%d",&num);
  ip = (int *)malloc(num * sizeof(int));
  emp = (int *)malloc(num * sizeof(int));
 
  for(int i = 0; i < num-1; i++){
    scanf("%d",&ip[i]);
    emp[--ip[i]]++;
  }

  for(int i=0; i < num; i++){
    printf("%d\n",emp[i]);
  }
  return 0;
}

Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
string s;
int n,g[1010101],ans;
int sl(int nww)
{
	int a=0,b=0,nw=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='?')
		{
			if(nw+1+g[i+1]<=nww)
			{
				nw+=1;
			}
			else
			{
				nw--;
			}
		}
		else if(s[i]=='1')
		{
			nw++;
		}
		else
		{
			nw--;
		}
		a=max(a,nw);
		b=min(b,nw);
	}
	return a-b;
}
int main()
{
	cin>>s;
	n=s.size();
	s=' '+s;
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='1')
		{
			g[i]=max(0,g[i+1]+1);
		}
		else
		{
			g[i]=max(0,g[i+1]-1);
		}
	}
	ans=min(sl(g[1]),sl(g[1]+1));
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FRO freopen("in.txt","r",stdin);

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);


      int n,i,j



	return 0;
}

cout<<"Case "<<++tt<<": No"<<endl;

#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FRO freopen("in.txt","r",stdin);

int arr[100005],dp[100005];
int fun(int n)
{
      if(dp[n]!=-1) return dp[n];
      if(n==2) return dp[2]=abs(arr[1]-arr[2]);
      return dp[n]=min(fun(n-1)+abs(arr[n]-arr[n-1]),fun(n-2)+abs(arr[n]-arr[n-2]));
}



int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);


      int n,i,j;
      cin>>n;
      memset(dp,-1,sizeof dp);
      for(i=1;i<=n;i++) cin>>arr[i];
      dp[0]=0;
      dp[1]=0;
      arr[0]=0;

      cout<<fun(n);



	return 0;
}



Measured memory_bytes: 2560
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s

#main
#n=int(input)
A,B,C=map(int,input().split())
#A=list(map(int,input().split()))
Yn(len(set([A,B,C]))==2)




Measured memory_bytes: 66156
#include<bits/stdc++.h>
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int n, m;
signed main() {
	while (cin >> n >> m, n) {
		string ans; for1(i, n + 2)ans += '#';
		for1(v1lah, m) {
			char ch; cin >> ch;
			if (ch == 'A') {
				for1(i, n)if (ans[i] == '#') { ans[i] = ch; break; }
			}
			else if (ch == 'B') {
				for (int i = n; i > 0; i--)if (ans[i] == '#' && ans[i - 1] != 'A' && ans[i + 1] != 'A') { ans[i] = ch; goto heavenb; }
				for1(i, n)if (ans[i] == '#') { ans[i] = ch; break; }
			heavenb:;
			}
			else if (ch == 'C') {
				if (v1lah == 1)ans[n / 2 + 1] = ch;
				else for1(i, n)if (ans[i] != '#') { if (i != n && ans[i + 1] == '#') { ans[i + 1] = ch; break; }if (i != 1 && ans[i - 1] == '#') { ans[i - 1] = ch; break; } }
			}
			else {
				if (v1lah == 1)ans[1] = ch;
				else {
					int a[110]; a[0] = n + 1;
					for1(i, n) {
						if (ans[i] == '#')a[i] = a[i - 1] + 1;
						else {
							a[i] = 0; int p = i - 1;
							while (p >= 1) { if (a[p] > a[p + 1] + 1)a[p] = a[p + 1] + 1; else break; p--; }
						}
					}
					int p = 1;
					for1(i, n)if (a[p] < a[i])p = i;
					ans[p] = ch;
				}
			}
		}
		cout << ans.substr(1, n) << endl;
	}
}


Measured memory_bytes: 3156
from pprint import pprint
from collections import deque, defaultdict

import sys

# n, q = map(int, input().strip().split(" "))
n, q = map(int, sys.stdin.readline().strip().split(" "))
edges = [[] for _ in range(n)]
for _ in range(n-1):
    # a_i, b_i = map(int, input().strip().split(" "))
    a_i, b_i = map(int, sys.stdin.readline().strip().split(" "))
    edges[a_i-1].append(b_i-1)
    edges[b_i-1].append(a_i-1)

counter = [0] * n
p = [0] * n
for _ in range(q):
    # p_i, x_i = map(int, input().strip().split(" "))
    p_i, x_i = map(int, sys.stdin.readline().strip().split(" "))
    counter[p_i-1] += x_i


parents = deque()
parents.append(0)
visited = set()
while parents:
    parent = parents.popleft()
    if parent in visited:
        continue
    visited.add(parent)
    for child in edges[parent]:
        if child in visited:
            continue
        counter[child] += counter[parent]
        # print("child")
        # print(child, counter[child])
        parents.append(child)

print(" ".join(list(map(str, counter))))

Measured memory_bytes: 121796
n = int(input())
l = []

for i in range(n):
    l.append(int(input()))

l.sort()
ans = sum(l)

if ans%10 == 0:
    for i in range(n):
        if l[i]%10 != 0:
            ans -= l[i]
            break

    else:
        ans = 0

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
//const double PI = acos(-1);
const int mod = 1000000007;

// ----------------------DEBUG TEMPLATE--------------------------
void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif
// =========================DEBUG TEMPLATE============================





int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        int x;
        cin>>x;
        if(x>=30){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }

    }
}


Measured memory_bytes: 3648
n = int(input())
st = []
for i in range(n):
    st.append([str(i) for i in input().split()])
x = str(input())

a = 0
for i in range(n):
    if st[i][0] == x:
        a = i
        break
ans = 0
for i in range(a+1, n):
    ans += int(st[i][1])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
ll lcm(ll l,ll a){
    return a/__gcd(l,a)*l;
}
ll exp(ll a, ll b,ll c){
  if(b==0)return 1;
  if(b%2==0){
    ll t =exp(a,b/2,c);
    return t*t%c;
  }
  else return exp(a,b-1,c)*a%c;
}
const ll big=1000000007;


int main(){
    int s,w;cin >> s >> w;
    string ans;
    if(s<=w)ans="unsafe";
    else ans="safe";
    cout << ans << endl;
}

Measured memory_bytes: 3636
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto a = aryread();
    a.sort();
    a ~= INF;
    // a.writeln();
    auto t = new long[](MAX);
    long cnt;
    foreach (i; iota(n))
    {
        if (!t[a[i]])
        {
            if (i + 1 < a.length && a[i] != a[i + 1])
                cnt++;
            long tmp;
            while (a[i] * tmp < MAX)
            {
                t[a[i] * tmp++]++;
            }
        }
    }
    cnt.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 17648
from itertools import accumulate


N = int(input())
S = input()

black = [0]*N
white = [0]*N

for i, s in enumerate(S):
    if s == '#':
        black[i] = 1
    else:
        white[i] = 1

# 累積和
black = [0] + black
black = list(accumulate(black))
white = [0] + white[::-1]
white = list(accumulate(white))[::-1]

ans = []
for i in range(N+1):
    ans.append(black[i] + white[i])

print(min(ans))

Measured memory_bytes: 78028
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    h = int(input())
    w = int(input())
    n = int(input())
    ans = 0
    if n % max(h,w) == 0:
        ans = n // max(h,w)
    else:
        ans = n // max(h,w) + 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38636
h, w = (int(i) for i in input().split())
s = [[j for j in input()] for i in range(h)]
for i in range(h):
    for j in range(w):
        cnt = 0
        if s[i][j] == "#":
            continue
        for k in range(-1,2):
            for l in range(-1,2):
                if 0 <= i+k <= h-1 and 0 <= j+l <= w-1 and s[i+k][j+l] == "#":
                    cnt += 1
        s[i][j] = str(cnt)

for i in s:
    print(*i,sep="")

Measured memory_bytes: 3572
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		ArrayList<Integer> input = new ArrayList<Integer>();
		int max = 0;
		int price = 0;
		int count = 0;
		int sum = 0;

		try {
			Scanner scanner = new Scanner(System.in);
			int x = scanner.nextInt();

			for (int i = 0; i < x; i++) {
				price = scanner.nextInt();
				input.add(price);
				if (max < price) {
					max = price;
					count = i;
				}
			}
			scanner.close();

			for (int i = 0; i < x; i++) {
				if (i == count) {
					sum = sum + input.get(i) / 2;
				} else {
					sum = sum + input.get(i);
				}
			}

			System.out.println(sum);
		} catch (InputMismatchException e) {
			System.out.println("整数を入力してください。");
		}

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	string s; cin >> s;
	
	cout << s.substr(0, s.size() - 8) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;



int main(void) {
  int i,j;
  int n,y;
  while(1){
    cin>>n;
    if(n==0)break;
    cin>>y;
    vi b(n),r(n),t(n);
    rep(i,n)cin>>b[i]>>r[i]>>t[i];
    double m=0,tmp;
    int ans=0;
    rep(i,n){
      if(t[i]==1)tmp=1+y*r[i]*0.01;
      else{
        tmp=1;
        rep(j,y)tmp*=1+r[i]*0.01;
      }
      if(tmp>m)ans=i,m=tmp;
    }
    cout<<b[ans]<<endl;
  }
}

Measured memory_bytes: 3004
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int N; 
std::string s; 
int sol(bool isSHEEP0, bool isSHEEP1, bool print = false) {
  std::vector<bool> isSHEEP(N);
  isSHEEP[0] = isSHEEP0;
  isSHEEP[1] = isSHEEP1;
  for(int i=2; i<N; i++) {
    if ( s[i-1] == 'o' && isSHEEP[i-1]  ) isSHEEP[i] =  isSHEEP[i-2];
    if ( s[i-1] == 'x' && isSHEEP[i-1]  ) isSHEEP[i] = !isSHEEP[i-2];
    if ( s[i-1] == 'o' && !isSHEEP[i-1] ) isSHEEP[i] = !isSHEEP[i-2];
    if ( s[i-1] == 'x' && !isSHEEP[i-1] ) isSHEEP[i] = isSHEEP[i-2];
  }

  if ( print ) {
    rep(i,N) { if ( isSHEEP[i] ) std::cout << "S"; else std::cout << "W"; }
    std::cout << std::endl;
  }

  auto check = [&](int x) -> bool {
    if ( s[x] == 'o' &&  isSHEEP[x] ) return isSHEEP[(x-1+N)%N] ==  isSHEEP[(x+1)%N];
    if ( s[x] == 'x' &&  isSHEEP[x] ) return isSHEEP[(x-1+N)%N] == !isSHEEP[(x+1)%N];
    if ( s[x] == 'o' && !isSHEEP[x] ) return isSHEEP[(x-1+N)%N] == !isSHEEP[(x+1)%N];
    if ( s[x] == 'x' && !isSHEEP[x] ) return isSHEEP[(x-1+N)%N] ==  isSHEEP[(x+1)%N];
    return false;
  };
  if ( check(N-1) && check(0) ) return true;
  else return false;
}

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::cin >> N;
  std::cin >> s;

  bool rtn = false;
  rtn = sol(true, true);
  if ( rtn ) {
    sol(true,true,true);
    return 0;
  }

  rtn = sol(false, true);
  if ( rtn ) {
    sol(false,true,true);
    return 0;
  }

  rtn = sol(true, false);
  if ( rtn ) {
    sol(true,false,true);
    return 0;
  }

  rtn = sol(false, false);
  if ( rtn ) {
    sol(false,false,true);
    return 0;
  }

  std::cout << -1 << std::endl;  

  
  return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 1e5 + 5;

ll a[maxn];
int n;
ll L;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> L;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    int pos = -1;
    for(int i = 1;i < n;i++){
        if(a[i] + a[i + 1] >= L){
            pos = i;
            break;
        }
    }
    if(pos == -1){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        for(int j = 1;j < pos;j++){
            cout << j << endl;
        }
        for(int j = n - 1;j > pos;j--){
            cout << j << endl;
        }
        cout << pos << endl;
    }
    return 0;
}


Measured memory_bytes: 4436
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <climits>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
using namespace std;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define fi first
#define se second
#define ii pair<int, int>
#define ll long long
#define endl "\n"
long double pi = 3.141592654;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	//freopen("Test.inp", "r", stdin);
	//freopen("Test.out", "w", stdout);
	int n;
	cin >> n;
	cout << pi * 2 * n;
	return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
 int a,n,cnt,w,check;
 vector<int> A;
 char s[1500];
 
 cin>>s;
 cin>>w;

 for(int i=0; i<strlen(s); i+=w)std::cout<<s[i];

 std::cout<<std::endl;


}

Measured memory_bytes: 256
S = input()
if len(S) > 9 or S.count("A") > 4 or S.count("K") != 1 or S.count("I") != 1 or S.count("H") != 1 or S.count("B") != 1 or S.count("R") != 1:
    print("NO")
else:
    S2 = S.translate(str.maketrans({'A': None, 'K': None, 'I': None, 'H': None, 'B': None, 'R': None}))
    if len(S2) != 0:
        print("NO")

    else:
        L = ["K", "I", "H", "B", "R", " "]
        r = 0
        i = 0
        while i < len(S):
            next_exp = L[r]

            if i == len(S) - 1:
                if S[i] == "A" and next_exp == " ":
                    print("YES")
                    break

                if S[i] == "R" and next_exp == "R":
                    print("YES")
                    break

                print("NO")
                break

            if S[i] == "A":
                if next_exp in ["I", "H"]:
                    print("NO")
                    break

                else:
                    if S[i + 1] != next_exp:
                        print("NO")
                        break
                    else:
                        r += 1
                        i += 2
                        continue

            if S[i] == next_exp:
                r += 1
                i += 1
                continue

            print("NO")
            break

        if i >= len(S):
            if L[r] == " ":
                print("YES")
            else:
                print("NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    string S;
    int Q;
    cin >> S >> Q;
    deque<char> dq;
    rep(i,SZ(S)) {
        dq.push_back(S[i]);
    }
    int dir = 0;
    rep(_q, Q) {
        int t; cin >> t;
        if(t == 1) {
            dir ^= 1;
        } else {
            int f; cin >> f;
            char c; cin >> c;
            if(f == 1) {
                if(dir == 0) dq.push_front(c);
                else dq.push_back(c);
            } else {
                if(dir == 0) dq.push_back(c);
                else dq.push_front(c);
            }
        }
    }
    if(dir == 1) reverse(ALL(dq));
    for(auto e : dq) cout << e;
    cout << endl;
    return 0;
}


Measured memory_bytes: 896