akhauriyash/Code-Regression huggingface dataset:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,K = map(int,input().split())

Ans = []
for i in range(N-1):
    Ans.append((N-1,i))

cnt = (N-1)*(N-2)//2
if cnt < K:
    print(-1)
    sys.exit()

for i in range(N-1):
    for j in range(i+1,N-1):
        if cnt>K:
            Ans.append((i,j))
            cnt -= 1

print(len(Ans))
for u,v in Ans:
    print(u+1,v+1)


Measured memory_bytes: 3956
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

typedef pair<int, int> P;

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

int main()
{
	char map[32][32];
	queue< P > que;
	while (true)
	{
		int w, h, x, y;
		cin >> w >> h;
		if (!(w || h)) break;
		for (int i = 0; i < h; i++)
		{
			cin >> map[i];
			char* x0 = index(map[i], '@');
			if (x0 != NULL)
			{
				x = x0 - map[i];
				y = i;
			}
		}
		int count = 0;
		que.push(P(x, y));
		map[y][x] = '#';
		while (!que.empty())
		{
			P current = que.front();
			que.pop();
			count++;
			for (int i = 0; i < 4; i++)
			{
				int nx = current.first + dx[i];
				int ny = current.second + dy[i];
				if ((0 <= nx && nx < w && 0 <= ny && ny < h) && (map[ny][nx] == '.'))
				{
					que.push(P(nx, ny));
					map[ny][nx] = '#';
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

int main()
{
    int n,k;
    std::cin>>n>>k;
    std::vector<int> v(n);
    
    for(int i=0;i<n;i++){
        std::cin>>v[i];
    }
    n--;
    k--;
    int ans = (n + k - 1) / k;
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;++i)
const int INF = 1e9+7;

int main(){
  int H,W;
  cin >> H >> W;
  vi dh = {0,1,0,-1}, dw = {1,0,-1,0};
  vector<vector<char>> A(H,vector<char>(W));
  vector<vector<int>> B(H,vector<int>(W));
  rep(i,H){
    rep(j,W){
      cin >> A.at(i).at(j);
    }
  }
  queue<P> q;
  rep(i,H){
    rep(j,W){
      B.at(i).at(j) = INF;
      if(A.at(i).at(j)=='#'){
        q.push(P(i,j));
        B.at(i).at(j) = 0;
      }
    }
  }
  int m = 0;
  while(q.size()){
    P p = q.front(); q.pop();
    rep(k,4){
      int nh = p.first + dh.at(k);
      int nw = p.second + dw.at(k);
      if(0<=nh&&nh<H&&0<=nw&&nw<W&&A.at(nh).at(nw)=='.'&&B.at(nh).at(nw)==INF){
        A.at(nh).at(nw) = '#';
        B.at(nh).at(nw) = min(B.at(nh).at(nw), (B.at(p.first).at(p.second) + 1));
        q.push(P(nh,nw));
        m = max(m,B.at(nh).at(nw));
      }
    }
  }
  cout << m << endl;
}


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

int main() {
  int d;
  cin >> d;
 if(d==25) cout << "Christmas" <<endl;
  if(d==24) cout << "Christmas Eve" << endl;
  if(d==23) cout << "Christmas Eve Eve" <<endl;
  if(d==22) cout << "Christmas Eve Eve Eve" <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define REP(i,N) for(int i=0;i<N;i++)
int main(){
    int n,m; cin>>n>>m;
    vector<vector<int>> v(m,vector<int>());
    vector<int> p;
    for(int i=0;i<m;i++){
        int k; cin>>k;
        for(int j=0;j<k;j++){
            int s; cin>>s;
            v[i].push_back(s-1);
        }
    }
    for(int i=0;i<m;i++){
        int a; cin>>a;
        p.push_back(a);
    }

    int ans = 0;
    for(int i=0;i<pow(2,n);i++){
        int lit = 0;
        for(int j=0;j<m;j++){
            int on = 0;
            for(auto s:v.at(j)){
                on += !(!(i&(1<<s)));
            }
            if(on%2==p.at(j)){
                lit++;
            }
        }
        if(lit==m){
            ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  cout<<((n-1)/111+1)*111<<endl;
  
  return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
int main() {
int n, i, j = 0, f = 1, x = 0, y;
int a[1000];
scanf("%d", &n);
for (i = 0;i < n;i++) {
scanf("%d", &a[i]);
}
while (f) {
f = 0;
for (i = n - 1;i > 0;i--) {
if (a[i] < a[i - 1]) {
y = a[i];
a[i] = a[i - 1];
a[i - 1] = y;
f = 1;
x++;
} } } for (i = 0;i < n;i++) {
if (i == n - 1) {
printf("%d\n%d\n", a[i], x);
} else {
printf("%d ", a[i]);
} } 
return 0;
}


Measured memory_bytes: 2104
N, M = map(int, input().split())
a_list = []
b_list = []
for i in range(M):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

par = [i for i in range(N+1)]
rank = [0]*(N+1)
size = [1] * (N + 1)

def find(x):
    if par[x] == x:
        return par[x]
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x, y):
    x_par = find(x)
    y_par = find(y)
    if x_par == y_par:
        return
    if rank[x_par] < rank[y_par]:
        par[x_par] = y_par
        size[y_par] += size[x_par]
    else:
        par[y_par] = x_par
        size[x_par] += size[y_par]
        if rank[x_par] == rank[y_par]:
            rank[x_par] += 1


def bool_func(x, y):
    if find(x) == find(y):
        return True
    else:
        return False


ans_list = []      
ans = int(N*(N-1)/2)
for i in range(M):
    ans_list.append(ans)
    a = a_list[M-1-i]
    b = b_list[M-1-i]
    p = size[find(a)]
    q = size[find(b)]
    if bool_func(a, b):
        pass
    else:
        ans -= p*q
        unite(a, b)

for i in range(M):
    print(ans_list[M-1-i])
    

Measured memory_bytes: 19404
#include <bits/stdc++.h>
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++)
using Graph = vector<vector<int>>;
using ll = long long;


int main() {
    int n;
    cin>>n;
    if(n%1000==0){
        cout<<0<<endl;
        return 0;
    }
    cout<<1000-n%1000<<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(){
  double a,b,c,d,e,f;
  double det,x,y;
  while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF){
    y = (a*f - c*d) / (a*e - b*d);
    x = (c - b*y) / a;
    printf("%.3lf %.3lf\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define SZ(s) ((int)(s.size()))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ALL(a) (a).begin(), (a).end()
typedef pair<int,int> PI;
typedef long long ll;

int app[100][100];
ll cost[100][100];

int main(int argc, char *argv[])
{
  int n;
  cin >> n;
  rep(i, n){
    char c;
    int b;
    cin >> c >> b;
    app[c-'A'][b] = 1;
  }

  int m;
  cin >> m;
  rep(i, 100) rep(j, 100) cost[i][j] = 1LL << 40LL;
  
  rep(j, m){
    char c;
    int b;
    ll e;
    cin >> c >> b >> e;
    cost[c-'A'][b] = min(cost[c-'A'][b], e);
  }
  
  ll ans = 1LL << 40;
  
  
  rep(used, 1 << 10){
    static ll dp[2][1<<10] = {};
    
    int needalpha[30] = {};
    rep(i, 26) rep(j, 10){
      if(app[i][j] && ((~used>>j)&1))
        needalpha[i] = 1;
    }
    
    rep(i,2) rep(k, 1<< 10) dp[i][k] = 1LL << 40LL;
    
    int cur = 0;
    dp[cur][0] = 0;
    rep(i, 26){
      int ne = 1 - cur;
      rep(j, 1 << 10) dp[ne][j] = 1LL << 40LL;
      
      if(!needalpha[i]){
        rep(j, 1 << 10) dp[ne][j] = min(dp[ne][j], dp[cur][j]);
      }

      // rep(j, 1 << 10) rep(k, 10){
      //   if(j&(1<<k)) continue;
      //   dp[cur][j|(1<<k)] = min(dp[cur][j|(1<<k)], dp[cur][j] + cost[i-1][k]);
      // }
      
      rep(j, 1 << 10){
        rep(k, 10){
          dp[ne][j|(1<<k)] = min(dp[ne][j|(1<<k)], dp[cur][j] + cost[i][k]);
        }
      }
      
      rep(j, 1 << 10) rep(k, 10){
        //if(j&(1<<k)) continue;
        dp[ne][j|(1<<k)] = min(dp[ne][j|(1<<k)], dp[ne][j] + cost[i][k]);
      }
      
      cur = 1 - cur;
    }
    
    rep(i, 1 << 10){
      if((i&used) == used){
        ans = min(ans, dp[cur][i]);
        // if(ans == 7){
        //   cout << used << ' ' << i << endl;
        //   return 0;
        // }
      }
    }
  }
  
  if(ans >= (1LL << 40LL)) cout << -1 << endl;
  else cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
 lint digit(lint);

int main(){

    lint n;
    cin >> n;

    lint a, b;
    cin >> a >> b;

    if(a == 0 && b == 0){
        cout << 0 << endl;
        return 0;
    }

    lint ans = (n/(a+b))*a;

    n -= ((a+b) * (n/(a+b)));

    if(n > a)ans += a;
    else ans += n;

    cout << ans << endl;

}
lint digit(lint num){
    lint dig = 0;
    while(num){
        num /= 10;
        ++dig;
    }
    return dig;
}

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

using namespace std;

#define int long long
#define sz(x) (int)x.size()
#define yes cout << "Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ft first
#define sd second
#define FOR(i, b, n) for(int i=b;i<n;i++)
#define REP(i, n) FOR(i, 0, n)
using pii = pair<int, int>;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vd = vector<double>;
mt19937_64 rnd(time(0));

void start() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    // cerr << fixed << setprecision(10);
#ifdef MY
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}

signed main() {
    start();
    int a;
    cin >> a;
    cout << a+a*a+a*a*a;



}








Measured memory_bytes: 3608
/*******************************************c#
* 20.04.16 AtCoder Beginner Contest 159. C - Maximum Volume
*
*
*********************************************/
/*********************************************

::test input::

*********************************************/
using System; //Console, IComparable
using System.IO; //StreamWriter 
using System.Linq; //Select(), Where(), OrderBy(), Count()
using System.Collections.Generic; //List<T>
using System.Reflection; //PropertyInfo[], GetProperties[]
using static System.Console; using static IOmacro.CInput;

namespace Nalgo {
    public class combination {
        public long combs(int n, int r) {
            if (n == r || r == 0) return 1L;
            else return combs(n-1, r-1) + combs(n-1, r);
        }
    }
    
}


namespace tempName {
    public class CRun{
        private static class gv{
            public static int N;
            public static int[] A;
            public static int[] H;
        }
    
        public void build(){            
            gv.N = _int;
            gv.A = _inta;
            gv.H = new int[gv.N +2]; Array.Clear(gv.H, 0, gv.H.Length);
            foreach (var x in gv.A) {
                gv.H[x]++;
            }
        }
    
        public void solve(){
            var algo = new Nalgo.combination();
            
            long ans = 0;
            
            foreach (long x in gv.H) {
                ans += (x >= 2 ? x*(x-1)/2 : 0);
            }
            
            foreach (var x in gv.A) {
                long ans_buf = ans;
                int H_now = gv.H[x];
                
                ans_buf -= (H_now >= 2 ? (long)(H_now -1) : 0L);
                Console.WriteLine(ans_buf);
            }
            //_writer.Close();
            
            
        }
    }

    class Program { 
        static void Main() { 
            var run = new CRun();
            run.build();
            run.solve();
            
            
        } 
    }
}

namespace IOmacro {
    public static class CInput {
        public static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput());
        public static string _string{get{return Console.ReadLine();}}
        public static string[] _stringa{get{return (Console.ReadLine().Split());}}
        public static int _int{get{return int.Parse(Console.ReadLine());}}
        public static int[] _inta{get{return Console.ReadLine().Split().Select(x=>int.Parse(x)).ToArray();}}
        public static long _long{get{return long.Parse(Console.ReadLine());}}
        public static long[] _longa{get{return Console.ReadLine().Split().Select(x=>long.Parse(x)).ToArray();}}    
    }
}


Measured memory_bytes: 35392
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	int ar[n][3];
	for(int i=0;i<n;i++) {
		for(int j=0;j<3;j++) {
			cin>>ar[i][j];
		}
	}
	int dp[n][3];
	for(int i=0;i<n;i++) {
		for(int j=0;j<3;j++) {
			dp[i][j] = 0;
		}
	}
	dp[0][0] = ar[0][0];
	dp[0][1] = ar[0][1];
	dp[0][2] = ar[0][2];
	for(int i=1;i<n;i++) {
		for(int j=0;j<3;j++) {
			for(int k=0;k<3;k++) {
				if(k!=j) {
					dp[i][j] = max(dp[i][j],dp[i-1][k] + ar[i][j]);
				}
			}
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 5964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
	return 0;
}



Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
    int n, m, i, count, j;
    char arr[100][100];
    scanf("%d%d", &n, &m);
    for (i=0; i<n; i++){
        for (j=0; j<m; j++){
            scanf(" %c", &arr[i][j]);
        }
    }
    for (i=0; i<n; i++){
        for (j=0; j<m; j++){
                count = 0;
            if (arr[i][j] == '.'){
                if (i-1 >= 0 && arr[i-1][j] == '#') count ++; ///
                if (i-1 >= 0 && j-1 >= 0 && arr[i-1][j-1] == '#') count ++;
                if (i-1 >= 0 && j+1 < m && arr[i-1][j+1] == '#') count ++; ///
                if (j-1 >= 0 && arr[i][j-1] == '#') count ++; ///
                if (j+1 < m && arr[i][j+1] == '#') count ++;///
                if (i+1 < n && arr[i+1][j] == '#') count ++;///
                if (i+1 < n && j-1 >= 0 && arr[i+1][j-1] == '#') count ++;
                if (i+1 < n && j+1 < m && arr[i+1][j+1] == '#') count ++;

                arr[i][j] = count + '0' ;
            }
        }
    }


    for (i=0; i<n; i++){
        for (j=0; j<m; j++){
            printf("%c", arr[i][j]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 1656
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

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

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

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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



int main() {

	string s;
	cin >> s;
	ll N = s.size();


	map<ll, ll> dp;
	dp[0] = 1;
	ll v = 0;
	repn(i, N) {
		ll x = s[i - 1] - 'a';
		v = v ^ (1 << x);

		if (dp[v] == 0) { dp[v] = INF; }

		rep(j, 26) {
			ll u = v ^ (1 << j);
			if (dp[u] != 0) {
				dp[v] = min(dp[v], dp[u] + 1);
			}
		}
	}

	dp[v]--;
	cout << max(1, dp[v]);

	

	system("PAUSE");
}


Measured memory_bytes: 272508
#include<iostream>
#include<math.h>
using namespace std;
long long int mini(long long int *h,long long int *dp,long long int i,long long int n)
{
  if(i==n-1)
    return 0;
  if(dp[i]!=-1)
    return dp[i];
  long long int val1=abs(h[i]-h[i+1])+mini(h,dp,i+1,n);
  long long int val2=abs(h[i]-h[i+2])+mini(h,dp,i+2,n);
  dp[i]=val1<val2?val1:val2;
  return dp[i];
}
int main(void)
{
  long long int n;
  cin>>n;
  long long int h[n],dp[n];
  long long int i;
  for(i=0;i<n;i++)
  {
    cin>>h[i];
    dp[i]=-1;
  }
  long long int ans=mini(h,dp,0,n);
  cout<<ans;
  return 0;
}


Measured memory_bytes: 11136
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
	vector<string> words;

	string str,tmp,tmpl;
	int max=0;
	int maxl=0;

	while(cin>>str)
		words.push_back(str);
	for(int i=0;i<words.size();i++){
		int c=0;
		int cl=words.at(i).size();
		for(int j=i+1;j<words.size();j++){
			if(words.at(i)==words.at(j)){
				c++;
			}
		}
		if(c>max){
			max=c;
			tmp=words.at(i);
		}
		if(cl>maxl){
			maxl=cl;
			tmpl=words.at(i);
		}
	}

	cout<<tmp<<" "<<tmpl<<endl;
	return 0;
}

Measured memory_bytes: 1208
S =  str(input())
m = list(set(S))
cnt_first = 0
cnt_second = 0
if len(m) == 2:
    first = m[0]
    sec = m[1]
    for i in range(len(S)):
        if S[i] == first:
            cnt_first += 1
        elif S[i] == sec:
            cnt_second += 1
else:
    print("No")
    exit()
if cnt_first == 2 and cnt_second == 2:
    print("Yes")


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  string str;
  cin>>n>>str;
  int count=0;
  for(int i=0;i<n-2;i++)
  {
    if(str.substr(i,3)=="ABC")
      count++;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  int n= 200001;
  char S[n];
  char T[n];
  int count=0;
  int ret = 0;
  ret = scanf("%s\n", S);
  ret = scanf("%s\n", T);
  int size = strlen(S);
  for(int i=0; i< size; i++){
    if(S[i]!=T[i]){
      count++;
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 2072
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author P.Alizadeh
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll,ll>     pll;
typedef complex<ld>     cld;

#define all(x)          x.begin(),x.end()
#define Sort(x)         sort(all(x))
#define kill(x)         return cout << x << endl, 0;
#define Mp              make_pair
#define X               first
#define Y               second
#define sep             " "
#define endl            "\n"
#define fastio          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define ld_io           cout << setprecision(10) << fixed;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll md) {
    if (!b)
        return 1;
    if (b & 1)
        return a * pw(a * a % md, b / 2, md) % md;
    return pw(a * a % md, b / 2, md) % md;
}

const ll MAXN = 400 + 10,
         INF  = 8e18,
         MOD  = 1e9 + 7,
         LOG  = 32;
//const ld PI   = M_PI;

ll n, a[MAXN], dp[MAXN][MAXN], sz[MAXN][MAXN];

int main()
{
    fastio;
    //ld_io;

    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> a[i];

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j + i < n; j++) {
            if (i == 0)
                sz[j][j] = a[j];
            else
                sz[j][j+i] = sz[j+1][j+i] + a[j];
        }
    }

    for (ll i = 1; i < n; i++) {
        for (ll j = 0; j + i < n; j++) {
            dp[j][j+i] = INF;
            for (ll k = j + 1; k <= j + i; k++) {
                dp[j][j+i] = min(dp[j][j+i], dp[j][k-1] + dp[k][j+i] + sz[j][j+i]);
            }
        }
    }

    cout << dp[0][n-1] << endl;

    return 0;
}



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

signed main() {
  
  int N, D;
  cin >> N >> D;
  vector<vector<int>> dot(N,vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> dot.at(i).at(j);
    }
  }

  int count;
  int sum;
  for (int i = 0; i < N; i++) {
  for (int l = 0; l < N; l++) {
    sum = 0;
    for (int j = 0; j < D; j++) {
      sum += pow((dot.at(i).at(j) - dot.at(l).at(j)), 2);
    }
    for (int k = 1; k < 1000; k++) {
      if (sum == pow(k, 2)) count++;
    }
  }
  }
  cout << count / 2 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	
	ll N,M;
	cin>>N>>M;
	vector<pair<int,int> >V;
	//V.push_back(make_pair(-1,-1));
	REP(i,M){
		int X,Y;
		cin>>X>>Y;
		V.push_back(make_pair(Y,X));
	}
	SORT(V);
	//FOR(i,0,M) cout<<V[i].second<<" "<<V[i].first<<endl;
	int x=0,co=0;
	REP(i,M){
		if(V[i].second<=x) continue;
		else{
			co++;
			x=V[i].first-1;
		}
	}
	cout<<co<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N)cin>>a[i];
    vector<ll> b(N);
    rep(i,N)cin>>b[i];
    ll ans = 0;
    rep(k, 30){
        ll T = bit(k);
        vector<ll> amod(N);
        vector<ll> bmod(N);
        rep(i,N){
            amod[i] = a[i] % (2 * T);
            bmod[i] = b[i] % (2 * T);
        }
        sort(all(bmod));
        ll sum = 0;
        rep(i,N){
            // T <= a + b < 2T
            sum += lower_bound(all(bmod), 2 * T - amod[i]) - lower_bound(all(bmod), T - amod[i]);
            // 3T <= a + b < 4T
            sum += lower_bound(all(bmod), 4 * T - amod[i]) - lower_bound(all(bmod), 3 * T - amod[i]);
        }
        if(sum % 2 == 1)ans += T;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6572
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	int w, n;
	string str;
	cin >> w >> n;
	int ami[30];
	for (int i = 0; i < w; i++) {
		ami[i] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		int a, b, temp;
		string str;
		scanf("%d, %d",&a, &b);
		temp = ami[a-1];
		ami[a-1] = ami[b-1];
		ami[b-1] = temp;
	}
	for (int i = 0; i < w; i++) {
	cout << ami[i] <<endl;
	}
	
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {
	
}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]) OUT("Yes");
	else OUT("No");
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()


void solution(){


	string s, t; cin >> s >> t;

	int m = s.size(), n = t.size();

	pii dp[m+1][n+1];

	for(int i = 0; i <= m; i++){
		dp[i][0] = {0,0};
	}
	for(int i = 0; i <= n; i++){
		dp[0][i] = {0,0};
	}

	pii cur = {-1,-1};
	int best = 0;

	for(int i = 1; i <= (int)s.size(); i++){
		for(int j = 1; j <= (int)t.size(); j++){
			if(s[i-1] == t[j-1]){
				dp[i][j] = {1 + dp[i-1][j-1].F, 3};
			}
			else{
				if(dp[i][j-1].F < dp[i-1][j].F){
					dp[i][j] = {dp[i-1][j].F, 2};
				} 
				else{
					dp[i][j] = {dp[i][j-1].F, 1};
				}
			}
			if(best <= dp[i][j].F){
				best = dp[i][j].F;
				cur = {i,j};
			}
		}
	}

	string ans = "";

	while(cur.F > 0 && cur.S > 0){
		pii p = dp[cur.F][cur.S];
		if(p.S == 3){
			ans.push_back(s[cur.F - 1]);
			cur.F--;
			cur.S--;
		}
		else if(p.S == 1) cur.S--;
		else cur.F--;
	}

	reverse(all(ans));
	cout << ans << endl;






}	


int main(){ 

	fio; // fast input output
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// GOOGLE //
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}

Measured memory_bytes: 73956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int n,a[111111];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	int ans=a[0];
	for(int i=1;i<n;i++)ans=gcd(ans,a[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

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

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int main(){
  string s;cin>>s;
  string t="AKIHABARA";

  int m=t.size();
  REP(bit,(1<<m)){
    string tmp;
    bool ok=true;
    REP(i,m){
      if(bit>>i&1) tmp+=t[i];
      else if(t[i]!='A') ok=false;
    }
    
    if(ok && s==tmp){
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}





Measured memory_bytes: 764
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let (a, b) = {
        let i = read::<isize>();
        (i[0], i[1])
    };

    if a > 8 || b > 8 {
        println!(":(");
    } else {
        println!("Yay!");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n, W;
  cin >> n >> W;

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

  int dp[W + 10] = {};
  for (int lim = 0; lim <= W; lim++) {
    for (int j = 0; j < n; j++) {
      if (lim >= w[j]) {
        dp[lim] = max(dp[lim], dp[lim - w[j]] + v[j]);
      }
    }
  }

  cout << dp[W] << endl;

  return 0;
}


Measured memory_bytes: 3256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

ll L[100];

int main() {
    ll N;
    cin >> N;
    L[0] = 2;
    L[1] = 1;
    for (int i = 2; i < 100; i++) {
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[N] << endl;
}


Measured memory_bytes: 256
fun main() = ABC168D.main()

object ABC168D {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun main() {
        val (N, M) = readInts()
        val edges = (1..M).flatMap {
            val (A, B) = readInts()
            listOf(A - 1 to B - 1, B - 1 to A - 1)
        }.groupBy { it.first }.mapValues { it.value.map { it.second }.toSet() }

        val dests = (1..N).map { null as Int? }.toMutableList()

        val stack = mutableListOf(0)
        while (stack.isNotEmpty()) {
            val dest = stack.first()
            stack.removeAt(0)
            edges[dest]?.let { tos ->
                tos.forEach { to ->
                    if (dests[to] == null) {
                        dests[to] = dest
                        stack.add(to)
                    }
                }
            }
        }

        val valid = dests.all { it != null }
        println(valid.yesOrNo())
        if(valid){
            val ans = dests.drop(1).map { it?.plus(1) }
            println(ans.joinToString("\n"))
        }
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readLong() = readLine()!!.toLong()
    fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "Yes" else "No"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

Measured memory_bytes: 155180
#include<stdio.h>
int main(void){
  
  int num; 
  if(scanf("%d",&num)){
 
    if( (num+3)%10==0 || (num+30)%100==num%10 || (num+300)%1000==num%100 ){
      printf("Yes");
    }
    else{
      printf("No"); 
    }
  }
   
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
#define ll long long
#define MOD 1000000007
#define INF (int)1e9
#define EPS 1e-9
/*
	B. Comparing Strings
*/

int main(){
	int a,b; cin>>a>>b;
	if(a<=b){
		for(int i=1;i<=b;i++){
			cout<<a;
		}
	}
	else{
		for(int i=1;i<=a;i++){
			cout<<b;
		}
	}
    return 0;
}



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


#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back

int main(){
    ll n, m; cin >> n >> m;
    vector<ll> sw(n);
		rep(i,m) {
			ll k;
			cin >> k;
			rep(j,k) {
				int s;
				cin >> s;
				s--;
				sw[s] |= 1<<i;
			}
		}
    
    ll p = 0;
    rep(i, m) {
		int x;
		cin >> x;
		p |= x<<i;
	}
 
	ll ans = 0;
    for (int s = 0; s < (1<<n); s++) {
		int t = 0;
		for (int i = 0; i < n; i++) {
				if (s>>i & 1) t ^= sw[i];
		}
		if (t == p) ans++;
	}
 
	cout << ans << endl;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits//stdc++.h>

using namespace std;

int main()
{
    long long h, a, c ;
    cin >> h ;
    a = 0 ;
    c = 1 ;
    
    while ( h > 0 )
    {
        
        a = a + c ;
        c = c * 2 ;
        h = h / 2 ;
        
    }
    
    cout << a ;

    return 0;
}


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

using namespace std;
typedef long long ll;

int main(void) {
	int num, k, a, b, ans = 0, i, j;
	ll dis;
	cin >> num >> k;
	vector<vector<int>> d(num, vector<int>(k));
	for (i = 0; i < num; i++) {
		for (j = 0; j < k; j++)
			scanf("%d", &d[i][j]);
	}
	for (i = 0; i < num; i++) {
		for (j = i + 1; j < num; j++) {
			dis = 0;
			for (a = 0; a < k; a++) {
				dis += (d[i][a] - d[j][a]) * (d[i][a] - d[j][a]);
			}
			b = sqrt(dis);
			if (b * b == dis)
				ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}

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

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

    vector<int> ans;
    int cnt = 0;
    for(int i = a; i <= b; i++){
        ans.push_back(i);
        cnt++;
        if(cnt == k){
            break;
        }
    }
    cnt = 0;
    for(int i = b; i >= a; i--){
        ans.push_back(i);
        cnt++;
        if(cnt == k){
            break;
        }
    }

    sort(ans.begin(), ans.end());
    decltype(ans)::iterator res = unique(ans.begin(), ans.end());
    ans.erase(res, ans.end());

    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main(){
    int A, B; cin >> A >> B;

    if(A-2*B >=0){
        cout << A-2*B << endl;
    }

    else{
        cout << 0 << endl;
    }
}

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

int main(void) {
    string s;
    int first = -1, last = -1;
    cin >> s;
  	if (s.size() == 2) {
      if (s[0] == s[1]) {
      	first = 1;
        last = 2;
      }
    }
    else {
      for (int i = 0; i <= s.size() - 3; i++) {
        	int count[26] = {};
        	bool flag = false;
        	for (int j = 0; j < 3; j++)
            	count[s[i + j] - 'a']++;
        	for (int j = 0; j < 26; j++) {
      	      if (count[j] >= 2)
            	    flag = true;
        	}
        	if (flag) {
            	first = i + 1;
            	last = i + 3;
            	break;
        	}
    	}
    }
    cout << first << ' ' << last << endl;
}


Measured memory_bytes: 512
import sys

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

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


def main():

    N = in_n()
    A = list(in_na())

    if N == 1:
        print(A[0] // 2)
        exit()

    ans = 0
    for i in range(N):
        if A[i] >= 3:
            if A[i] % 2 == 0:
                ans += (A[i] - 2) // 2
                A[i] = 2
            else:
                ans += (A[i] - 1) // 2
                A[i] = 1

    for i in range(N - 1):
        if A[i] == 2 and A[i + 1] == 0:
            A[i] = 0
            ans += 1
        elif A[i] == 2 and A[i + 1] == 1:
            A[i], A[i + 1] = 0, 1
            ans += 1
        elif A[i] == 2 and A[i + 1] == 2:
            A[i], A[i + 1] = 0, 0
            ans += 2
        elif A[i] == 1 and A[i + 1] == 1:
            A[i], A[i + 1] = 0, 0
            ans += 1
        elif A[i] == 1 and A[i + 1] == 2:
            A[i], A[i + 1] = 0, 1
            ans += 1
        elif A[i] == 0 and A[i + 1] == 2:
            A[i], A[i + 1] = 0, 0
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18540
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7


n, m = map(int, input().split())
data = [list(map(int, input().split())) for i in range(m)]





l, r = 0, 10**6
for i, j in data:
	l = max(l, i)
	r = min(r, j)
print(max(0, r-l+1))


Measured memory_bytes: 56284
#include<iostream>
#include<cstdio>
#include<cstring>
#include <fstream>
#include<string>
#include<sstream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <math.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long long int MOD = 1000000007;
const int INF = 1000000007;
const double EPS = 1e-10;
const double PI = 3.14159265359;
const int N = 100005;
//cout << fixed << std::setprecision(9)
//--------------------------

ll dp[N][2];
vector<int> edge[N];
int n, u, v;

void dfs(int x, int last)
{
	dp[x][0] = dp[x][1] = 1;
	for (auto to : edge[x]) {
		if (to == last) continue;
		dfs(to, x);
		dp[x][0] = dp[x][0] * ((dp[to][0] + dp[to][1]) % MOD) % MOD;
		dp[x][1] = dp[x][1] * dp[to][0] % MOD;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}

	dfs(1, -1);
	cout << (dp[1][0] + dp[1][1]) % MOD << endl;

	return 0;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    string s;
    cin >> s;
    int ans = 1001;
    for(int i = 0; i+2 < s.size(); ++i){
        int temp = (s[i]-'0')*100 + (s[i+1]-'0')*10 +s[i+2]-'0';
        ans = min(ans, abs(temp-753));
    }
    cout << ans << endl;    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

bool sosuhantei(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return n!=1;
}

int main(){
  vector<int> v;
  for(int i=1;i<=55555;i+=5){
    if(sosuhantei(i)){
      v.push_back(i);
    }
  }
  
  int n;
  cin>>n;
  rep(i,0,n){
    cout<<v[i];
    if(i==n-1){
      cout<<endl;
    }
    else{
      cout<<' ';
    }
  }
}

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

using namespace std;

#define PI 3.14159265358979323846

int main()
{
	double a, b, c, s = 0.0, l = 0.0, h = 0.0, t = 0.0, x = 0.0;
	
	scanf("%lf %lf %lf", &a, &b, &c);
	
	t = c * PI / 180;
	s = 0.5 * a * b * sin(t);
	x = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(t));
	l = a + b + x;
	h = 2 * s / a;
	
	printf("%.8lf\n%.8lf\n%.8lf\n", s, l, h);
	
	return 0;
}


Measured memory_bytes: 3452
input = input().split()
a = int(input[0])
b = int(input[1])

if (a > b):
  at_code = a
  a = a - 1
else:
  at_code = b
  b = b - 1
 
if (a > b):
  at_code = at_code + a
else:
  at_code = at_code + b
 
print(at_code)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long 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
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,r;
   cin>>n>>r;
   if(n<10)
   {
       cout<<r+100*(10-n)<<endl;
   }
   else
    cout<<r<<endl;
}


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

int main() {
    int n, m, q; 
    cin >> n >> m >> q;
    vector<vector<int>> sum(n+1, vector<int>(n+1, 0) );
    for (int i = 0; i < m; i++){
        int left, right;
        cin >> left >> right;
        sum[left][right] = sum[left][right] + 1;
    }
    
    for (int k = 1; k < n; k++){
        for (int l = 1; l+k <= n; l++){
            int r = l + k;
            sum[l][r] = sum[l][r] + sum[l+1][r] + sum[l][r-1] - sum[l+1][r-1];
        }   
    }

    for (int i = 0; i < q; i++){
        int p1, p2;
        cin >> p1 >> p2;
        cout << sum[p1][p2] << endl;
    }

    return 0;
}


Measured memory_bytes: 4540
#include<bits/stdc++.h>
using namespace std;
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
string s;
int main(){
  cin>>s;ll N=s.size();
  bool judge=true;
 for(ll i=0;i<(N/2);i++)
   if(s[i]!=s[N-2-i])judge=false;
  
  if(s[0]=='0' ||s[N-1]=='1')judge=false;
  
  if(!judge)
    cout<<-1<<endl;
  else{
  vector<ll>A;
    for(ll i=0;i<N/2;i++)
      if(s[i]=='1')A.push_back(i+1);
    vector<vector<ll>>G(N+1);
    ll M=A.size();for(ll i=0;i<M-1;i++)
      G[i+1].push_back(i+2);
    ll I=M+1;
    for(ll i=1;i<M;i++){
    ll a=A[i-1];ll b=A[i];
      for(ll j=0;j<b-a-1;j++){
      G[i+1].push_back(I);I++;
      }
    
    }G[M].push_back(I);
    for(ll i=I+1;i<=N;i++)
      G[I].push_back(i);
    set<P>S;
    for(ll i=1;i<=N;i++)
      for(auto v:G[i]){
      P p(i,v);S.insert(p);
       }for(auto p:S){
      ll u=p.first;ll v=p.second;
        cout<<u<<" "<<v<<endl;
      }
  }
  return 0;
}

Measured memory_bytes: 14160