akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.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 MOD (1000000007)
#define vi vector<int>
#define vii vector<vi>

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

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


const ll INF = 1LL << 60;



int main(){
  int n; cin >> n;
  vi a(n); for(auto &x:a) cin >> x;
  int ans = a[0];

  for (int i = 1; i < n; i++) {
    ans = gcd(ans,a[i]);
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 640
N = int(input())
a = list(map(int, input().split()))

spell_cnt = 0
spelled = False
for i, color in enumerate(a[1:]):
    # print(a[i], color, spelled)
    if a[i] == color and not spelled:
        # print(i)
        spell_cnt += 1
        spelled = True
    else:
        spelled = False

print(spell_cnt)


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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main()
{
	std::ios_base::sync_with_stdio(0);
	
	u32 n;

	std::cin >> n;

	std::vector<std::pair<i32,i32>> v;
	v.reserve(n);

	for(u32 i=0; i<n; i++)
	{
		u32 x, y;
		std::cin >> x >> y;
		v.emplace_back(x, y);
	}

	std::vector<std::vector<long double>> m(n, std::vector<long double>(n, 0.f));

	for(u32 i=0; i<n; i++)
	{
		for(u32 j=0; j<n; j++)
		{
			if(i==j)
			{
				continue;
			}
			m[i][j] = std::sqrt(std::pow(v[i].first - v[j].first, 2) + std::pow(v[i].second - v[j].second, 2));
		}
	}

	long double sum = 0.f;
	for(u32 i=0; i<n; i++)
	{
		long double col_sum = 0.f;
		for(u32 j=0; j<n; j++)
		{
			col_sum += m[i][j];
		}
		sum += (col_sum*(n-1));
	}

	std::cout << std::fixed << std::setprecision(10) << (sum/((n*n)-n)) << "\n";
	
	return 0;
}

Measured memory_bytes: 256
K,N  = map(int,input().split())
Alist = list(map(int,input().split()))
p = 10**8
p = min(max((K-abs(Alist[0]-Alist[N-1])),abs(Alist[0]-Alist[N-1])),max((K-abs(Alist[0]-Alist[1])),abs(Alist[0]-Alist[1])),p)
for i in range(1,N-1):
    p = min(p,max((K-abs(Alist[i]-Alist[i-1])),abs(Alist[i]-Alist[i-1])),max((K-abs(Alist[i]-Alist[i+1])),abs(Alist[i]-Alist[i+1])))
p = min(p,max((K-abs(Alist[N-1]-Alist[N-2])),abs(Alist[N-1]-Alist[N-2])),max((K-abs(Alist[N-1]-Alist[0])),abs(Alist[N-1]-Alist[0])))
print(p)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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 MOD = 1000000007;
ll INF =1<<30;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int w;
    cin >> w;
    for(int i = 0;i<n;i+=w){
        cout << s[i] ;
    }
    cout << endl;
}

Measured memory_bytes: 3568
#include<math.h>
#include<string>
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
class Point
{
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) {return Point(x + p.x, y + p.y); }
    Point operator - (Point p) {return Point(x - p.x, y - p.y); }
    Point operator * (double a) {return Point(x * a, y * a);}
    Point operator / (double a) {return Point(x / a, y / a);}

    double abs() {return sqrt(norm());}
    double norm() {return x * x + y * y;}
    
    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const{
        return equals(x, p.x) && equals(y, p.y);
    }
};typedef Point Vector;

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}

int ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0, b = p2 - p0;
    if (cross(a, b) > EPS) return 1;
    if (cross(a, b) < -EPS) return -1;
    if (dot(a, b) < -EPS) return 2;
    if (a.norm() < b.norm()) return -2;
    return 0;
}
#include<iostream>
bool intersection(Point p0, Point p1, Point p2, Point p3){
    if (ccw(p0, p1, p2) == 0 || ccw(p0, p1, p3) == 0 || 
        ccw(p2, p3, p0) == 0 || ccw(p2, p3, p1) == 0)
        return true;
    if (ccw(p0, p1, p2) * ccw(p0, p1, p3) == -1 && ccw(p2, p3, p0) * ccw(p2, p3, p1) == -1)
        return true;
    return false;
}
int main(){
    int q; cin >> q;
    int x0, y0, x1, y1, x2, y2, x3, y3;
    Point p0, p1, p2, p3;
    for (int i = 0; i < q; i++)
    {
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        p0 = Point(x0, y0);
        p1 = Point(x1, y1);
        p2 = Point(x2, y2);
        p3 = Point(x3, y3);
        if(intersection(p0, p1, p2, p3)) cout << 1 << endl;
        else cout << 0 << endl;
    }   
}


Measured memory_bytes: 3112
#include<iostream>
#include<vector>
using ll =  long long;

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

using namespace std;

int main(){

    int k,a,b;
    cin >> k >> a >> b;
    int flag=0;

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

    return 0;


}

Measured memory_bytes: 3624
#include <iostream>

int main()
{
    int n,m,l;
    std::cin>>n>>m>>l;
    int A[100][100]={{}},B[100][100]={{}};

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            std::cin>>A[i][j];
        }
    }

    for(int i = 0; i < m; i++)
    {
        for(int j = 0; j < l; j++)
        {
            std::cin>>B[i][j];
        }
    }

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < l; j++)
        {
            long long int c = 0;
            for(int k = 0; k < m; k++)
            {
                c += A[i][k]*B[k][j];
            }
            if(j==l-1){std::cout<<c;}else{std::cout<<c<<" ";}
        }
        std::cout<<std::endl;
    }
    return 0;
}


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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, W, V = 0, ans = 0;
    cin >> n >> W;
    vector<int> w(n), v(n);
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
        V += v[i];
    }
    vector<vector<int> > dp(n + 1, vector<int>(V + 1, -1));
    dp[0][0] = W;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= V; j++) {
            if (dp[i][j] != -1) {
                // don't take i-th item
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                // take i-th item if you can
                if (dp[i][j] >= w[i]) {
                    dp[i + 1][j + v[i]] = max(dp[i + 1][j + v[i]], dp[i][j] - w[i]);
                    ans = max(ans, j + v[i]);
                }
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 40192
#include <stdio.h>

#define MIN(A,B) \
  ( (A) < (B) ? (A) : (B) )

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int p, j;
  int t;

  scanf ( "%d%d", &p, &t ); p = MIN( p, t );
  scanf ( "%d", &t );       p = MIN( p, t );
  scanf ( "%d%d", &j, &t ); j = MIN( j, t );
  printf ( "%d\n", p + j - 50 );

  return ( 0 );
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[200005],b[200005];
long long l,r,mid,ans;

bool check(long long x){
	for(int i=1;i<=n;i++){
		if(a[i]>x) b[i]=1;
		else b[i]=0;
	}
	int u=n/2+1;
	int v=u,w=u;
	while(b[v-1]!=b[v]&&v>1) v--;
	while(b[w+1]!=b[w]&&w<n) w++;
	if(v==1&&w==n){
		if(u&1) return b[u];
		else return b[u]^1;
	}
	if(u-v+1<w-u+1) return b[v];
	else return b[w];
}

int main(){
	scanf("%d",&n);
	n=2*n-1;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	l=0,r=1e10,ans=1e10+7;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)) l=mid+1;
		else{
			r=mid-1;
			ans=min(ans,mid);
		}
	}
	printf("%lld\n",ans);
	
	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInts();
            var list = new List<string>();
            int ii = 0;
            switch (NM[0])
            {
                case 1:
                    ii = 0;
                    break;
                case 2:
                    ii = 10;
                    break;
                case 3:
                    ii = 100;
                    break;
            }

            for (int i = 0; i < NM[1]; i++)
            {
                var sc = Read();
                list.Add(sc);
            }

            for (int i = ii; i < 1000; i++)
            {
                var b = true;
                for (int j = 0; j < list.Count; j++)
                {
                    var a = list[j].Split(' ');
                    var s = int.Parse(a[0]);
                    var c = int.Parse(a[1]);
                    var istr = i.ToString();
                    try
                    {
                        if (istr[s - 1] != c.ToString()[0])
                        {
                            b = false;
                        }
                    }
                    catch (Exception)
                    {
                        b = false;
                    }
                }
                if (b)
                {
                    //if (i == 0)
                    //{
                    //    WriteLine(-1);
                    //    return;
                    //}
                    WriteLine(i);
                    return;
                }
            }
            WriteLine(-1);

        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#include<stdlib.h>

int lcomp(const void *a,const void *b){
	if(*(long*)a == *(long*)b)return 0;
	return (*(long*)a<*(long*)b)?-1:1;
}

int main(void){
	int n;
	scanf("%d",&n);
	long ar[n];
	for(int i = 0;i < n;i++)scanf("%ld",&ar[i]);
	qsort(ar,n,sizeof(long),lcomp);
	unsigned long long cusar[n];
	cusar[0] = (unsigned long long)ar[0];
	for(int i = 1;i < n;i++)cusar[i] = cusar[i-1] + (unsigned long long)ar[i];
	int ans = 1;
	for(int i = n-2;i >= 0 && cusar[i] * 2 >= (unsigned long long)ar[i+1];i--)ans++;
	printf("%d",ans);
	return 0;
}


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

int main() {
  int64_t n;
  cin>>n;
  cout<<n*(n-1)/2<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define NIL -1
typedef struct{
  int left,right,parent;
}Tree;
void setDepth(int ,int );

int n,depth[100000];
Tree Node[100000];

int main(void){
  int i,j,node,parent,child,prev_child;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    Node[i].left=NIL;
    Node[i].right=NIL;
    Node[i].parent=NIL;
  }

  
  for(i=0;i<n;i++){
    scanf("%d%d",&node,&parent);
    for(j=0;j<parent;j++){
      scanf("%d",&child);
      if(j!=0)
	/*2,3,....,parent
	 right node(sibling) is added as child*/
	Node[prev_child].right=child;
      else
	//first step
	Node[node].left=child;
      prev_child=child;
      Node[child].parent=node;
    }
  }


  for(i=0;i<n;i++)
    //set root node number
    if(Node[i].parent==NIL)node=i;

  setDepth(node,0);

  i=0;
  while(i<n){
    printf("node %d: ",i);
    printf("parent = %d, ",Node[i].parent);
    printf("depth = %d, ",depth[i]);
    if(Node[i].parent==NIL)printf("root, [");
    else if(Node[i].left==NIL)
      printf("leaf, [");
    else
      printf("internal node, [");
    
    j=0;
    child=Node[i].left;
    while(child!=NIL){
      if(j++!=0)printf(", ");
      printf("%d",child);
      child=Node[child].right;
    }
    printf("]\n");
    i++;
  }
  return 0;
}
void setDepth(int node,int depth_node){
  depth[node]=depth_node;
  if(Node[node].right!=NIL)
    //If there is a right node(sibling),set depth of right node.
    setDepth(Node[node].right,depth_node);
  if(Node[node].left!=NIL)
    //If there is a left node(child),set depth of left node.
    setDepth(Node[node].left,++depth_node);
}



Measured memory_bytes: 6540
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) - 1 for _ in range(d)]

def scoring(d, c, s, t):
    v = []
    memo = [0 for _ in range(26)]
    for i in range(d):
        if i == 0:
            score = 0
        else:
            score = v[-1]
        score += s[i][t[i]]
        memo[t[i]] = i + 1
        for j in range(26):
            score -= c[j] * (i+1 - memo[j])

        v.append(score)

    return v

v = scoring(d, c, s, t)
print(*v, sep='\n')

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

using namespace std;

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

	int n;
	cin >> n;

	vector<int> a(n);
	for(int &i : a) {
		cin >> i;
	}

	vector<vector<int> > G(n);

	for(int i = 0; i < n - 1; ++i) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}

	vector<int> ans(n);

	int mx = *max_element(a.begin(), a.end());

	vector<int> dp(n, mx + 1);

	function<void(int, int)> dfs = [&] (int u, int f) {
		int p = lower_bound(dp.begin(), dp.end(), a[u]) - dp.begin();
		ans[u] = max(ans[u], p + 1);
		int tmp = dp[p];
		dp[p] = a[u];
		for(int v : G[u]) {
			if(v != f) {
				ans[v] = max(ans[v], ans[u]);
				dfs(v, u);
			}
		}
		dp[p] = tmp;
	};

	dfs(0, -1);

	for(int i : ans) {
		cout << i << '\n';
	}

	return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N;
  vector<llong> X;

  cin >> N;
  X.resize(N);
  for (auto &in: X) {
    cin >> in;
  }
  sort(ALL(X));

  llong ans = inf<llong>;
  for (int P = 0; P <= 101; ++P) {
    llong res = 0;
    for (auto &x: X) {
      res += (x - P) * (x - P);
    }

    ans = min(ans, res);
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(void){


    int n;
    cin >> n;

    mp m;
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        m[s] += 1;
    }

    cout << "AC x " << m["AC"] << "\n";
    cout << "WA x " << m["WA"] << "\n";
    cout << "TLE x " << m["TLE"] << "\n";
    cout << "RE x " << m["RE"] << "\n";

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector <int> num(N);
  for (int i = 0; i < N; i++) cin >> num.at(i);
  
  sort (num.begin(),num.end());
  
  cout << num.at(N-1) - num.at(0) << endl;
}

Measured memory_bytes: 256
#include <string>
#include <stack>
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
  string word;
  stack<int> S;
  int a,b;
  while (cin >> word) {
    if (word == "+"){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push( a + b );
    }
    else if (word == "-") {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push( b - a );
    }
    else if (word == "*") {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push( a * b );
    }
    else {
      S.push( atoi(word.c_str()) );
    }
  }
  cout << S.top() << endl;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int l;
    cin>>s;
    l=s.size();
    if(l%2==0)
     {
         int c=0,j=l-1;
         for(int i=0;i<l/2;i++)
          {

             if(s[i]!=s[j])
             c++;
             j--;
             }
             cout<<c;
     }
     else
     {
         int c=0,j=l-1;
         for(int i=0;i<l/2;i++)
          {
           if(s[i]!=s[j])
             c++;
             j--;
             }
        cout<<c;
     }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,h,w,ans=0;
	cin>>n>>h>>w;
	for(int i=0;i<n;i++)
	{
		int l,r;
		cin>>l>>r;
		if(l>=h && r>=w)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
} 

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

vector<int> e[100001];

int m[100001];

void First(){
	cout<<"First"<<endl;
	exit(0);
}

void dfs(int x,int p){
	for(int it:e[x])
		if(it!=p)
			dfs(it,x);
	if(m[x]==0){
		if(m[p]!=0)
			First();
		m[x]=p;
		m[p]=x;
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1,u,v;i<n;i++)
		cin>>u>>v,e[u].emplace_back(v),e[v].emplace_back(u);
	dfs(1,0);
	if(m[0]!=0)	First();
	cout<<"Second"<<endl;
}


Measured memory_bytes: 6144
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


/*--------------------------------------------------------------------------*/

//main関数
int main() {
    st w; cin >> w;
    vl alpha(26,0);

    rep(i,Size(w)){
        alpha[w[i] - 'a']++;
    }

    bool flag = true;
    rep(i,26){
        if(alpha[i] % 2 != 0){
            flag = false;
            break;
        }
    }
    Yes(flag);
}



Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    long long n, c, tmp, s, t;
    std::cin >> n >> c;
    std::vector<long long> num(200001, 0ll), ret(200001, 0ll);
    std::vector<std::vector<long long>> ch(c, std::vector<long long>(100001, 0ll));
    for (auto i = 0ll; i < n; i++) {
        std::cin >> s >> t >> tmp;
        tmp--;
        if (ch[tmp][s] == 0 && ch[tmp][t] == 0) {
            num[2 * s - 1]++;
            num[2 * t]--;
        } else if (ch[tmp][s] > 0 && ch[tmp][t] == 0) {
            num[2 * s]++;
            num[2 * t]--;
        } else if (ch[tmp][t] > 0 && ch[tmp][s] == 0) {
            num[2 * s - 1]++;
            num[2 * t - 1]--;
        } else {
            num[2 * s]++;
            num[2 * t - 1]--;
        }
        ch[tmp][t]++;
        ch[tmp][s]++;
    }
    for (auto i = 1ll; i < 200001; i++) {
        ret[i] = ret[i-1] + num[i];
    }
    std::cout << *std::max_element(ret.begin(), ret.end()) << std::endl;

    return 0;
}

Measured memory_bytes: 27776
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
int main(){
  long long a,ans=1;
  cin >> a;
  for(int i = 1;i <= a;i++){
    ans *= i;
    ans %= 1000000007;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  string n;
  cin>>n;
  bool ja=true;
  for(int i=1;i<len(n);i++){
    if(n[i]!='9') ja=false;
  }
  if(ja){
    cout<<(len(n)-1)*9+n[0]-'0'<<endl;
    return 0;
  }
  cout<<(len(n)-1)*9+n[0]-'0'-1<<endl;
}

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


int findSumOfDigits(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }

    return sum;

}

int main() {
    
    int n, a, b;

    cin >> n;
    
    int fx = findSumOfDigits(n);
    if (n%fx==0) {
       cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll INF = 1LL << 60; //MAX 9223372036854775807

template <typename flow_t>
struct FordFulkerson
{
  struct edge
  {
    ll to;
    flow_t cap;
    ll rev;
    bool isrev;
  };

  vector<vector<edge>> graph;
  vector<ll> used;
  const flow_t INF;
  ll timestamp;

  FordFulkerson(ll n) : INF(numeric_limits<flow_t>::max()), timestamp(0)
  {
    graph.resize(n);
    used.assign(n, -1);
  }

  void add_edge(ll from, ll to, flow_t cap)
  {
    graph[from].emplace_back((edge){to, cap, (ll)graph[to].size(), false});
    graph[to].emplace_back((edge){from, 0, (ll)graph[from].size() - 1, true});
  }

  flow_t dfs(ll idx, const ll t, flow_t flow)
  {
    if (idx == t)
      return flow;
    used[idx] = timestamp;
    for (auto &e : graph[idx])
    {
      if (e.cap > 0 && used[e.to] != timestamp)
      {
        flow_t d = dfs(e.to, t, min(flow, e.cap));
        if (d > 0)
        {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  flow_t max_flow(ll s, ll t)
  {
    flow_t flow = 0;
    for (flow_t f; (f = dfs(s, t, INF)) > 0; timestamp++)
    {
      flow += f;
    }
    return flow;
  }

  void output()
  {
    for (ll i = 0; i < graph.size(); i++)
    {
      for (auto &e : graph[i])
      {
        if (e.isrev)
          continue;
        auto &rev_e = graph[e.to][e.rev];
        cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
      }
    }
  }
};

int main()
{
ll n;
cin >> n;
vector<ll> a(n);
ll sum=0;
rep(i, n)
{
  cin >> a[i];
  if(a[i]>0)sum+=a[i];
}
FordFulkerson< ll > g(n+2);
rep(i,n){
if(a[i]>=0)g.add_edge(i+1,n+1,a[i]);
else g.add_edge(0,i+1,-a[i]);
}
rep(i,n){
  for (ll j = i+1; j <= n; j+=i+1)
  {
    g.add_edge(i+1,j,INF);
  }
}

ll ans = g.max_flow(0,n+1);


cout << sum-ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int64_t solve(vector<vector<int64_t> > &dp ,vector<int>&w,vector<int>&v,int i, int j){
    //価値がマイナスの場合を聞かれたら0を返す
    if (j < 0)
    {
        return 0 ;
    }
    
    if (dp.at(i).at(j) != -1)
    {
        return dp.at(i).at(j) ;
    }
    
    int64_t inf = 1000000000000 ;
    if (i == 0)
    {
        if (j <= v.at(i))
        {
            dp.at(i).at(j) = w.at(i) ;
            return w.at(i) ;
        }
        else
        {
            dp.at(i).at(j) = inf ;
            return inf ;
        }

    }else{
        dp.at(i).at(j) = min( solve(dp,w,v,i-1,j) , solve(dp,w,v,i-1,j-v.at(i))+w.at(i) ) ;
        return dp.at(i).at(j) ;
    }

}

int main(){
    int64_t inf = 1000000000000 ;
    int n , W ;
    cin >> n >> W ;
    vector<int> w(n) ;
    vector<int> v(n) ;
    int maxv = 0;
    for (size_t i = 0; i < n; i++)
    {
        /* code */
        cin >> w.at(i) >> v.at(i) ;
    }
    for (size_t i = 0; i < n; i++)
    {
        /* code */
        maxv += v.at(i) ;
    }
    
    vector<vector<int64_t> > dp(n,vector<int64_t>(maxv+1,-1));

    dp.at(0).at(0) = 0 ;
    for (size_t i = 1; i < maxv+1; i++)
    {
        solve(dp,w,v,n-1,i) ;        
    }
    
    
    for (size_t i = maxv; i > 0; i--)
    {
        if (dp.at(n-1).at(i) != -1 && dp.at(n-1).at(i) <= W)
        {
            
            cout << i << endl ;
            break;
        }
        
    }
    
    
    
}

Measured memory_bytes: 79360
N,W = map(int,input().split())
w = []
v = []
for i in range(N):
    x,y = map(int,input().split())
    w.append(x)
    v.append(y)

dp = [[0]*(W+1) for j in range(N+1)] # DPテーブルの作成

for i in range(N):
    for j in range(W+1):
        if j < w[i]: # 選ばない時
            dp[i+1][j] = dp[i][j]
        else: # 選ぶ時
            dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i])

print(dp[N][W])


Measured memory_bytes: 147340
#include <stdio.h>

int main(){
  int N,i;
  scanf("%d", &N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d", &A[i]);
  }
  double bunbo=0,bunsi=1,seki=1;
  for(i=0;i<N;i++){
    bunsi = bunsi*A[i];
  }
  for(i=0;i<N;i++){
    seki = seki*A[i];
  }
  for(i=0;i<N;i++){
    bunbo += seki/A[i];
  }
  printf("%le\n", bunsi/bunbo);
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  int n;
  const int max_n = 2 * 1e5;
  int a[max_n + 1];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];

  long long ans = 0;
  int current_min = a[0];
  for(int i = 1; i < n; i++){
    if(a[i] > current_min) {
      current_min = a[i];
    }else{
      ans += current_min - a[i];
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main()
{
    int count = 0;
    string str1, str2, str3;
    cin >> str1;
    vector<char> st(str1.size());
    for (int i = 0; i < str1.size();i++){
        if(str1.at(i)=='0'){
            st.at(count) = str1.at(i);
            count++;
        }
        else if (str1.at(i) == '1')
        {
            st.at(count) = str1.at(i);
            count++;
        }
        else{
            if(count!=0){
                count--;
            }
            //st.at(i) = str1.at(i);
        }
    }
    for (int i = 0; i < count;i++){
        cout << st.at(i) ;
    }
    cout << endl;
}

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

int a[210000],n,sum,f[210000],b1[210000],b2[210000],ans[210000],s1,s2;

int getach() {
    char ch=getchar();
    while(ch!='0'&&ch!='1') ch=getchar();
    return ch-'0';
}

int work(int x) {
    int temp=x,sum=0;
    while(temp) {
        if(temp&1) sum++;
        temp>>=1;
    }
    return x%sum;
}

int main() {
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        a[i]=getach();
    for(int i=1;i<=n;i++) sum+=a[i];
    for(int i=1;i<=sum;i++) {
        f[i]=f[work(i)]+1;
    }
    if(sum>1) for(int i=1,temp=1;i<=n;i++,temp=temp*2%(sum-1)) b1[i]=temp;
    for(int i=1,temp=1;i<=n;i++,temp=temp*2%(sum+1)) b2[i]=temp;
    for(int i=1;i<=n;i++) if(a[i]) {
        if(sum>1) s1=(s1+b1[n-i+1])%(sum-1);
        s2=(s2+b2[n-i+1])%(sum+1);
    }
    for(int i=1;i<=n;i++) {
        if(a[i]) {
            if(sum<=1) continue;
            int temp=(s1-b1[n-i+1]+sum-1)%(sum-1);
            ans[i]=f[temp]+1;
        }
        else {
            int temp=(s2+b2[n-i+1])%(sum+1);
            ans[i]=f[temp]+1;
        }
    }
    for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 7328
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        int q=sc.nextInt();
        int[] ln=new int[100001];
        for (int i = 3; i < 100000; i+=2) {
            if(isPrime(i)&&isPrime((i+1)/2)){
                ln[i]++;
            }
        }
        for (int i = 0; i < 100000; i++) {
            ln[i+1]+=ln[i];
        }
        for (int i = 0; i < q; i++) {
            int l=sc.nextInt();
            int r=sc.nextInt();
            out.println(ln[r]-ln[l-1]);
        }
        out.close();
    }

    static boolean isPrime(int p){
        int l=(int)sqrt(p);
        for (int i = 2; i <= l; i++) {
            if(p%i==0)return false;
        }
        return true;
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
}

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

int main() {
	int n;
	cin >> n;
	int x[n];
	int num[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		num[i] = x[i];
	}

	sort(num, num+n);
	int ans[num[n-1]] = {};
	for (int i = 1; i <= num[n-1]; i++) {
		for (int j = 0; j < n; j++) {
			ans[i-1] += (i - x[j]) * (i - x[j]);
		}
	}

	sort(ans, ans+num[n-1]);
	cout << ans[0] << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    while(true) {
        val (h, w) = readLine()!!.split(" ").map(String::toInt)
        if (h == 0 && w == 0) break
        for (i in 1..h) {
            for (j in 1..w) {
                if (i == 1 || i == h || j == 1 || j == w) print("#")
                else print(".")
            }
            println("")
        }
        println("")
    }
}


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

int main(){
    ostringstream oss;
    int a,b,ans=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        oss<<i;
        if((oss.str().at(0)==oss.str().at(4))&&(oss.str().at(1)==oss.str().at(3)))ans++;
        oss.str("");
        oss.clear();
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int N;
  vector<int> A(110);

  cin >> N;
  for (int i=0; i<N; i++) cin >> A[i];

  double a = 0;
  for (int i=0; i<N; i++){
    a += 1.0/A[i];
  }

  cout << setprecision(10);
  cout << 1.0 / a << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

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

	cin >> N;
	string s;
	cin >> s;
	while (M < N - 1) {
		if (s[M] != s[M + 1]) {
			K++;
			M++;
		}
		M++;
	}
	cout << K << endl;
}


Measured memory_bytes: 3348
import sys
import math
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import itertools
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
x = y = z = N / 3
print(x * y * z)


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

const int N = 1e5 + 3;
vector<ll> dp(N);    

ll frog(int n, ll ht[])
{
    dp[1] = 0;
    dp[2] = abs(ht[1] - ht[0]);
    for(int i = 3; i<=n; i++)
    {
        dp[i] = min((dp[i-1] + abs(ht[i-1] - ht[i-2])),(dp[i-2] + abs(ht[i-1] - ht[i-3])));
    }

    return dp[n];
}
int main()
{
    int n;
    cin >> n;
    ll arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];

    cout << frog(n, arr);

}

Measured memory_bytes: 4752
#include<stdio.h>

int main(){
	
	int n;
	scanf("%d",&n);
	int i,a[n];
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=n-1;i>=0;i-=1){
		if(i<n-1)printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
	
	return 0;
}



Measured memory_bytes: 2048
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i,j;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  double a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  double ans1=0,ans2=0,noudo = 0.0;
  std::vector<double> w,s;
  for(i = 0;i<=f;i+=100*a) {
    for(j = 0;j<=f; j+=100*b) {
      // cout<<i+j<<endl;
      if(i+j <= f) w.pb(i+j);
    }
  }
  ll lm = f*e/100;
  for(i = 0;i<=lm;i+=c) for(j = 0;j<=lm; j+=d) if(i+j <= f) s.pb(i+j);
  rep(i,w.size())rep(j,s.size()){
    if(w[i]==0) continue;
    if(w[i]*e/100 >= s[j]){
      if(w[i]+s[j] <= f && s[j] / w[i] >= noudo){
        // cout<<w[i]<<" "<<s[j]<<endl;
        ans1 = w[i] +s[j];
        ans2 = s[j];
        noudo = s[j] / w[i];
      }
    }
  }
  // cout<<w.size()<<" "<<s.size()<<endl;
  cout<<(int)ans1<<" "<<(int)ans2<<endl;
}

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


Measured memory_bytes: 2420
using System;
using System.Linq;

namespace Program
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            int count = 0;
            int evenCount;

            while (true)
            {
                evenCount = list.Count(x => x % 2 == 1);
                if (evenCount >= 1)
                {
                    break;
                }
                else
                {
                    list = list.Select(x => x / 2).ToList();
                }
                count++;
                
            }
            Console.WriteLine(count);
        }
    }
}



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

int main(){
    int a,b;
    while (true){
        cin>>a>>b;
        for(int t=0;t<a;t++){
            for(int h=0;h<b;h++){
                if(h!=b-1){
                   cout<<"#"; 
                }else{
                    cout<<"#"<<endl;
                }
            
                
            }
            
            
        }
    if(a==0&&b==0){
        break;
    }    
        cout<<endl;
        
    
        
    }
}


Measured memory_bytes: 3084
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int counts=0;
	int count=0;
	for(int i=0;s[i]!='\0';i++)
	{
		if(s[i]=='T'&&counts!=0)
		{
			counts--;
			count--;
		}
		else if(s[i]=='S')
		{
			counts++;
			count++;
		}
		else
		{
			count++;
		}
	}
	cout<<count;
} 

Measured memory_bytes: 640
N = int(input())
a = []
b = []
c = []
for i in range(N):
    num = list(map(int, input().split(' ')))
    a.append(num[0])
    b.append(num[1])
    c.append(num[2])
dp = [[0,0,0] for i in range(N)]
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]
for i in range(1, N):
    dp[i][0] = max(dp[i -1][1] + a[i], dp[i -1][2] + a[i])
    dp[i][1] = max(dp[i -1][0] + b[i], dp[i -1][2] + b[i])
    dp[i][2] = max(dp[i -1][0] + c[i], dp[i -1][1] + c[i])
ans = max(dp[N -1][0], dp[N -1][1], dp[N -1][2])
print(ans)

Measured memory_bytes: 40680
#include <bits/stdc++.h>
using namespace std;
 
const int INF= 1001001001;
vector<int> a;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    int n;
    int ans = 0;
    cin >> n;
    if(n >= 82){
        cout << "No" << endl;
        return 0;
    }
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(n == i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){	
      //   #ifndef ONLINE_JUDGE
      //  // for getting input from input.txt
      //  freopen("input.txt", "r", stdin);
      //  // for writing output to output.txt
      //  freopen("output.txt", "w", stdout);
      // #endif
       string s;
       int maxs=0,g=0;
       cin>>s;
       for (int i = 0; i <= s.length(); ++i)
       {
         if((s[i] == 'A' ||s[i] == 'C' ||s[i] == 'G' ||s[i] == 'T'))
        {
          g++;
            
          maxs = max(maxs,g); 
        }
        else{
          g = 0;
        }
       }
       cout<<maxs<<endl;
       return 0;
 }


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=100000,inf=0x3f3f3f3f;
int n,m,fa[maxn+10],minv[maxn+10],minid[maxn+10],id[maxn+10];
bool ban[maxn+10]; int a[maxn+10]; ll ans;
int getf(int x){return fa[x]==x?x:fa[x]=getf(fa[x]);}
bool cmp(int x,int y){return a[x]<a[y];}
int main(){
	scanf("%d%d",&n,&m); int ndd=(n-1-m)*2;
	if(ndd>n){
		printf("Impossible"); return 0;
	}
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]); fa[i]=id[i]=i; minv[i]=inf;
	}
	for(int i=1;i<=m;++i){
		int l,r; scanf("%d%d",&l,&r); ++l; ++r;
		fa[getf(l)]=getf(r);
	}
	for(int i=1;i<=n;++i){
		int p=getf(i);
		if(a[i]<minv[p]) minv[p]=a[i],minid[p]=i;
	}
	int cnt=0; 
	for(int i=1;i<=n;++i) if(getf(i)==i){
		++cnt;
		ans+=minv[i]; ban[minid[i]]=1; --ndd; 
	}
	if(cnt==1){
		printf("0"); return 0;
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1,j=1;i<=ndd;++i){
		for(;ban[id[j]];j++); ans+=a[id[j++]];
	}
	printf("%lld",ans);
}

Measured memory_bytes: 2304
s = gets.chomp.split("").map &:to_s
t = gets.chomp.split("").map &:to_s
n = s.length
m = t.length
k = -1
(n-m).downto(0) do |i|
  m.times do |j|
    break unless s[i+j] == t[j] || s[i+j] == "?"
    k = i if j == m - 1
  end
  break if k != -1
end
if k == -1
  puts "UNRESTORABLE"
else
  n.times do |i|
    if i < k || i > k + m - 1
      s[i] = "a" if s[i] == "?"
    else
      s[i] = t[i-k]
    end
  end
  puts s.join("")
end

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<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; }
lli calc(lli num){
    return num*num*num*num*num;
}

void func(long long X){

    vector<lli> v;
    map<lli,lli> d;
    set<lli> s;

    for(lli i=-1000;;i++){
        lli num = calc(i);
        LOG2(i,num);
        if(num>=1e15)break;
        v.push_back(num);
        d[num] = i;
        s.insert(num);
    }

    REP(i,0,v.size()){
        lli num = X+v[i];
        if(s.find(num)!=s.end()){
            cout<<d[num]<<" "<<-1000+i<<endl;
            return ;
        }
    }


}

int main(){
    // cout << fixed << setprecision(5);

    long long X;
    scanf("%lld",&X);
    func(X);
    return 0;
}


Measured memory_bytes: 3932
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  double a, b, n;
  cin >> a >> b >> n;

  double x = min(b - 1, n);
  ll ans = floor(a * x / b) - a * floor(x / b);
  cout << ans << endl;
}


Measured memory_bytes: 3700
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    prime_num = [1]*1001
    for n in range(2,N+1,1):
        while n % 2 == 0:
            prime_num[2] += 1
            n //= 2
        
        f = 3
        while f * f <= n:
            while n % f == 0:
                prime_num[f] += 1
                n //= f
            f += 2
        if n != 1:
            prime_num[n] += 1
    ans = 1
    for i in range(1001):
        ans *=prime_num[i]
    print(ans % (10**9+7))
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T>
inline void remax(T& x, T y) { x = max(x, y); }

template<typename T>
inline void remin(T& x, T y) { x = min(x, y); }

int main() 
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}





Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main(){
    ll n;cin>>n;
    ll a[n];
    ll sum=0;
    ll mini=inf;
    ll c=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<0){
            c++;
        }
        sum=sum+abs(a[i]);
        mini=min(mini,abs(a[i]));
    }
    if(c%2==1){
        cout<<sum-2*mini<<endl;
    }else{
        cout<<sum<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int n=sz(s);

    int res=0;
    
    rep(i,n){
        while(s[i]==s[i+1] && i<n-1) i++;
        if(i==n-1) break;
        res++;
    }    
    cout<<res<<endl;
}

Measured memory_bytes: 3684