akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define endl '\n'
#define tab " "
#define lli long long int


void read(){
    int d;
    vector<int> D;

    for(int i = 0; i < 3; ++i){
        cin >> d;
        D.push_back(d);
    }

    sort(D.begin(), D.end());

    cout << D[0]+D[1] << endl;
}

int main(void){
    read();
    return 0;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define int long long

using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second)
        return (a.second < b.second);
    else
        return (a.first < b.first);
}

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

    int n, a, b;
    vector<pair<int, int>> p;
    cin >> n;
    while (n--)
    {
        cin >> a >> b;
        p.push_back({a - b, a + b});
    }
    sort(p.begin(), p.end(), cmp);

    int l = -1e18, ans = 0;
    for (auto i : p)
    {
        if (i.first < l)
            continue;
        else
            l = i.second, ans++;
    }
    cout << ans << '\n';

    return 0;
}

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

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

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int cost[n+1];
    for(int i=0;i<n;i++)cost[i]=1000000000;
    //memset(cost,INT_MAX,sizeof(cost));
    cost[0]=0;
    for(int i=0;i<n;i++){
        if(i+2<n){
            int diff=abs(arr[i+2]-arr[i]);
            cost[i+2]=min(cost[i+2],cost[i]+diff);
        }
        if(i+1<n){
            int diff=abs(arr[i+1]-arr[i]);
            cost[i+1]=min(cost[i+1],cost[i]+diff);
        }
    }
    cout<<cost[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;

	if(a > b){
		cout << a + a - 1 << "\n";
	}else if(a < b){
		cout << b + b - 1 << "\n";
	}else{
		cout << a + b << "\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include <functional>
#include <limits>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

//https://atcoder.jp/contests/agc023/tasks/agc023_a


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, K;
	int res = 0;
	vector<int> a, sum, sum2, v, con;
	
	cin>>N;
	
	a.resize(N);
	sum.resize(N+1);
	sum2.resize(N+1);
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
	}
	
	for(int i = 0; i < N; i++){
		sum[i+1] += sum[i] + a[i];
		v.push_back(sum[i+1]);
	}
	
	v.push_back(0);
	
	sort(v.begin(), v.end());
	
	v.erase(unique(v.begin(), v.end()), v.end());
	
	
	con.resize(v.size());
	
	for(int i = 0; i <= N; i++){
		sum2[i] = lower_bound(v.begin(), v.end(), sum[i]) - v.begin();
	}
	
	con[sum2[0]]++;
	
	for(int i = 0; i < N; i++){
		
		res += con[sum2[i+1]];
		con[sum2[i+1]]++;
	}
	
	cout<<res<<endl;
	
	
	return 0;
}

Measured memory_bytes: 8176
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N,K;
	scanf("%d %d",&N,&K);

	int tmp,ans = 0;

	for(int i = 0; i < N; i++){

		scanf("%d",&tmp);
		if(tmp >= K){

			ans++;
		}
	}

	printf("%d\n",ans);

	return 0;
}


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

using namespace std;
int n, m, k;
int ans = 0;

void dfs(int a, int b)
{
	if(a == 0)
	{
		ans += b - k <= 0 ? 1 : b - k;
		//cout << ans << endl;
	}
	else
	{
		for(int i = 1; i <= m; ++i)
		{
			dfs(a - 1, b + i);
		}
	}
}

void solve()
{
	while(cin >> n >> m >> k, n || m || k)
	{
		ans = 0;
		dfs(n, 0);
		printf("%.8f\n", ans / pow((double)m, n));
	}
}

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

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

int main() {
  string S, T;
  cin >> S >> T;
  int n;
  n = S.size();
  int i = 0;
  int m = 0;
  
  for(i; i<n; i++) {
    if (S.at(i) != T.at(i)) {
      m += 1;
    }
  }
  if (m > 0) {
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}
    

Measured memory_bytes: 3632
using System;

namespace AtCoder
{
	public class ProblemA
	{
		public static void Main(string[] args)
		{
			string[] line = Console.ReadLine().Split(' ');
			int k = int.Parse(line[0]);
			int s = int.Parse(line[1]);

			int count = 0;

			int limit = Math.Min(k, s);
			for (int i = Math.Max(0, s - 2 * k); i <= limit; i++)
			{
				int tmp = s - i;
				int start = Math.Max(0, tmp - k);
				int end = Math.Min(k, tmp);
				count += end - start + 1;
			}

			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 27284
N, M = map(int, input().split())
memo = [[] for _ in range(M)]

for i in range(M):
    k, *s = map(int, input().split())
    # sの中身は-1して使用する
    memo[i] = s

P = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    tmp = 0
    for idx, light in enumerate(memo):
        on_switches = 0
        for j in range(N):
            if i >> j & 1:
                if j+1 in light:
                    on_switches += 1
        if on_switches % 2 == P[idx]:
            tmp += 1
    if tmp == M:
        ans += 1

print(ans)


Measured memory_bytes: 3064
n, a, b = map(int,input().split())
ans = 0

if a >= n:
    ans = n
elif a+b >= n:
    ans = a
else:
    set_ab = n//(a+b)
    ans += set_ab*a
    n -= set_ab*(a+b)
    if n < a:
        ans += n
    else:
        ans += a

print(ans)


Measured memory_bytes: 9140
#include<stdio.h>
int main()
{
    int N;
  	scanf("%d",&N);
  	int i=0;
    int a[N];
  	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
    }
  	int test = 0;
  	int check = 0;
  	for(i=0;i<N;i++){
		if((a[i] %2) ==0){
          test++;
			 if((a[i]%3) ==0){
               check++;
             }else if((a[i]%5) == 0){
				check++;
             }
        }
    }
  
  if(test == check){
	printf("APPROVED");
  }else{
	printf("DENIED");
  }
 
  
    return 0;
}


Measured memory_bytes: 128
N = int(input())
lst = list(map(int, input().split()))
cnt = 0
while sum(lst) > 0:
    idx0s = [idx for idx, i in enumerate(lst) if i == 0]
    if len(idx0s) == 0:
        for i in range(N):
            lst[i] -= 1
        cnt += 1
    else:
        if idx0s[0] != 0 and sum(lst[:idx0s[0]]) > 0:
            for i in range(idx0s[0]):
                lst[i] -= 1
            cnt += 1
        if idx0s[-1] != len(lst) - 1 and sum(lst[idx0s[-1]+1:]) > 0:
            for i in range(idx0s[-1]+1, len(lst)):
                lst[i] -= 1
            cnt += 1
        if len(idx0s) >= 2:
            for i in range(len(idx0s)-1):
                l = idx0s[i]
                r = idx0s[i+1]
                if l+1 < r:
                    for i in range(l+1, r):
                        lst[i] -= 1
                    cnt += 1


print(cnt)

Measured memory_bytes: 41072
#include<stdio.h>
int main(void){
  int a, b, c, d, e, f, g, h, sumA, sumB;

  scanf("%d %d %d %d", &a, &b, &c, &d);
  scanf("%d %d %d %d", &e, &f, &g, &h);
  sumA = a + b + c + d;
  sumB = e + f + g + h;
  if(sumA >= sumB){
    printf("%d\n", sumA);
  }
  else if(sumA < sumB){
    printf("%d\n", sumB);
  }
  return 0;
}

Measured memory_bytes: 0
//嘘解法
#include <iostream>
#include <string>
using namespace std;
 
string s;
 
int main() {
	cin >> s;
	
	int turn = 0;
	
	if (s[0] == s[s.length() - 1]) {
		turn = s.length() - 3;
	}
	else {
		turn = s.length() - 2;
	}
	
	if (turn % 2) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MAX_V 1000
#define INF 1000000000000
using Edge = struct{
  int from;
  int to;
  long cost;
};

int V, E;
long d[MAX_V];
vector<Edge> edge;

bool Bellman_Ford(int s) {
  for (int i=1; i<V; i++)
    d[i] = INF;
  d[s] = 0;
  for (int i=0; i<V; i++) {
    for (int j=0; j<E; j++) {
      Edge e = edge[j];
      if (d[e.from] == INF)
        continue;
      if (d[e.to] > d[e.from]+e.cost) {
        d[e.to] = d[e.from] + e.cost;
        if (i == V-1 && e.to == V-1)
          return true;
      }
    }
  }
  return false;
}

int main() {
  cin >> V >> E;
  int a, b;
  long c;
  for (int i=0; i<E; i++) {
    cin >> a >> b >> c;
    a--;
    b--;
    edge.push_back({a, b, -c});
  }
  bool loop = Bellman_Ford(0);
  if (loop)
    cout << "inf\n";
  else
    cout << -d[V-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int deg=1;

    int ans=1;

    int n;cin>>n;
    vector<int>h(n);
    for(int i=0;i<n;i++)cin>>h[i];

    while(true){
        int cnt=0;
        for(int i=0;i<h.size();i++){
            if(h[i]!=0)cnt++;
        }
        if(cnt<=deg*4)break;
        ans+=deg*4;
        for(int i=0;i<h.size();i++)h[i]=max(0ll,h[i]-1);
        deg++;
    }

    for(int i=0;i<h.size();i++)ans+=h[i];

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

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

ll amax = 1e6;

int main(){

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

    ll n; cin >> n;
    ll a[n];
    set<ll> st;
    set<ll> ng;
    rep(i, n){
        cin >> a[i];
        if(st.find(a[i]) == st.end()){
            st.insert(a[i]);
        }
        else{
            ng.insert(a[i]);
        }
    }

    sort(a, a+n);

    bool is_forbidden[amax + 1];
    rep(i, amax + 1){
        is_forbidden[i] = false;
    }

    for(ll t : st){
        if(is_forbidden[t]) continue;

        ll prod = t;
        while(true){
            prod += t;
            if(prod > amax) break;

            is_forbidden[prod] = true;
        }
    }

    ll cnt = 0;
    rep(i, n){
        if(is_forbidden[a[i]]){
            continue;
        }
    
        if(!(ng.find(a[i]) == ng.end())){
            continue;
        }

        cnt++;
    }

    cout << cnt << endl;


    return 0;
}

Measured memory_bytes: 15536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	map<string,int>mp;
	while(n--)
	{
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<'\n';
	cout<<"WA x "<<mp["WA"]<<'\n';
	cout<<"TLE x "<<mp["TLE"]<<'\n';
	cout<<"RE x "<<mp["RE"]<<'\n';
	return 0;
}

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

#define ull unsigned long long

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    long long N, K;
    cin >> N >> K;
    cout << min(N % K, K - (N % K));
    return 0;
}


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

int main(void){
    int h,w;
    cin >> h >> w;
    char c[h][w];
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            cin >> c[i][j];
        }
    }
    bool check = true;
    for(int i = 0,j = 0;i < h && j < w;){
        c[i][j] = '.';
        if(c[i+1][j] == '#')i++;
        else if(c[i][j+1] == '#')j++;
        else {
            break;
        }
    }
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(c[i][j] == '#')check = false;
            //cout << c[i][j];
        }
        //cout << endl;
    }
    if(check == false)cout << "Impossible";
    else cout << "Possible";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
	return '"' + s + '"';
}

string to_string(const char *s)
{
	return to_string((string)s);
}

string to_string(bool b)
{
	return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++)
	{
		if (!first)
		{
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
	string res = "";
	for (size_t i = 0; i < N; i++)
	{
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v)
{
	bool first = true;
	string res = "{";
	for (const auto &x : v)
	{
		if (!first)
		{
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
	ll A, B, M, ans = inf;
	cin >> A >> B >> M;
	vector<ll> a(A), b(B);
	for (int i = 0; i < A; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < B; i++)
	{
		cin >> b[i];
	}
	ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
	for (int i = 0; i < M; i++)
	{
		ll x, y, c;
		cin >> x >> y >> c;
		x--, y--;
		ans = min(ans, a[x] + b[y] - c);
	}
	cout << ans << "\n";
}

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

int main(){
  int N;
  cin >> N;
  int h[N];
  for (int i = 0; i < N; i++)
    cin >> h[i];
  int ans = 0;
  int active = 0;
  for (int i = 0; i < N; i++)
  {
    if (active < h[i])
      ans += h[i] - active;
    active = h[i];
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<set>
#include<queue>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,col[100005],vis[100005],ans[100005],x,y;
set<int> s[100005];
vector<int> bi[100005];
priority_queue<pair<int,int>/**/> pq;
int main()
{
	cin>>n;
	for (i=1;i<n;i++)
	{
		cin>>x>>y;
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	cin>>m;
	for (i=1;i<=m;i++)
	{
		cin>>x>>y;
		ans[x]=y;
		vis[x]=1;
		pq.push(make_pair(y,x));
	}
	/*col[1]=1;
	if (!dfs(1))
	{
		cout<<"No";
		return 0;
	}*/
	//cout<<"Yes"<<endl;
	while (!pq.empty())
	{
		y=pq.top().first;x=pq.top().second;
		pq.pop();
		for (i=0;i<bi[x].size();i++)
		{
			if (vis[bi[x][i]]) continue;
			vis[bi[x][i]]=1;
			ans[bi[x][i]]=y-1;
			pq.push(make_pair(y-1,bi[x][i]));
		}
	}
	for (i=1;i<=n;i++)
	{
		for (j=0;j<bi[i].size();j++)
		{
			if (abs(ans[bi[i][j]]-ans[i])!=1)
			{
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	for (i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
}

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

vector<vector<int>> G;

void dfs(int current, int pre, vector<int> &d) {
  for (int next : G.at(current)) {
    if (next == pre) continue;
    d.at(next) = d.at(current) + 1;
    dfs(next, current, d);
  }
}

int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--; v--;

  G.resize(N);
  rep(i, N - 1) {
    int A, B;
    cin >> A >> B;
    A--; B--;

    G.at(A).push_back(B);
    G.at(B).push_back(A);
  }

  vector<int> du(N, 0); // uからの距離
  du.at(u) = 0;
  vector<int> dv(N, 0); // vからの距離
  dv.at(v) = 0;

  dfs(u, -1, du);
  dfs(v, -1, dv);

  int d = 0;
  rep(i, N) {
    if (du.at(i) >= dv.at(i)) continue;
    d = max(d, dv.at(i));
  }
  cout << d - 1 << endl;
  return 0;
}

Measured memory_bytes: 12928
using System;
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            double [,]hen=new double[n,3];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                hen[i, 0] = int.Parse(s[0]);
                hen[i, 1] = int.Parse(s[1]);
                hen[i, 2] = int.Parse(s[2]);
            }
            for (int i = 0; i < n; i++)
            {
                hen[i, 0] = Math.Pow(hen[i, 0], 2);
                hen[i, 1] = Math.Pow(hen[i, 1], 2);
                hen[i, 2] = Math.Pow(hen[i, 2], 2);
                if (hen[i, 0] == (hen[i, 1] + hen[i, 2]) || hen[i, 1] == (hen[i, 0] + hen[i, 2])||hen[i, 2] == (hen[i, 0] + hen[i, 1])) 
                { 
                    Console.WriteLine("YES"); 
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
        }
    }

Measured memory_bytes: 5520
#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,K;
	cin >> A >> B >> K;
	int m = min(A,B);
	int cnt = 1;
	for (int i = m; i > 0; --i)
	{
		if (A % i == 0 && B % i == 0)
		{
			if (cnt != K)
			{
				cnt++;
			}
			else
			{
				cout << i << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int d;

	cin >> d;

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

	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int mn = 0, mx = 0;
    int mni = -1, mxi = -1;
    int A[N+3];
    for(int i = 0; i < N; ++i) {
        cin >> A[i]; 
        if(A[i] < mn) { mni = i + 1; mn = A[i]; }
        else if(A[i] > mx) { mxi = i + 1; mx = A[i]; }
    }

    if(mni == -1) {
        cout << N-1 << endl;
        for(int i = 1; i < N; ++i)
            cout << i << " " << i + 1 << endl;
    } else {
        if(mxi == -1) {
            cout << N-1 << endl;
            for(int i = N; i > 1; --i) 
                cout << i << " " << i - 1 << endl;
        }
        else if(abs(mx) >= abs(mn)) {
            cout << 2*N-2 << endl;
            for(int i = 1; i <= N; ++i) 
                if(i != mxi) 
                    cout << mxi << " " << i << endl;
            for(int i = 1; i < N; ++i) 
                cout << i << " " << i + 1 << endl;
        }
        else {
            cout << 2*N-2 << endl;
            for(int i = 1; i <= N; ++i) 
                if(i != mni)
                    cout << mni << " " << i << endl;
            for(int i = N; i > 1; --i) 
                cout << i << " " << i - 1 << endl;
        }
    }

    return 0;
}

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

int main() {
    int r, c;
    cin >> r >> c;
    vector< vector<int> > v(r + 1, vector<int>(c + 1, 0));
    
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> v.at(i).at(j);
            v.at(i).at(c) += v.at(i).at(j);
        }
    }
    
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < r; j++) {
            v.at(r).at(i) += v.at(j).at(i);
            v.at(r).at(c) += v.at(j).at(i);
        }
    }
    
    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            cout << v.at(i).at(j);
            if (j == c) {
                cout << endl;
            } else {
                cout << ' ';
            }
        }
    }
}


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//最終奥義 #define int long long
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; }
//lambda: [](int x, int y){return x<y;}

const int MAX=1000002;
const int MOD=1000000007;
ll finv[MAX],inv[MAX];

void COMinit() {
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll loop_sq(ll n,ll r){
    if(r==0) return 1;
    if(r % 2) return loop_sq(n, r - 1) % MOD * n % MOD;
    else return loop_sq(n * n % MOD, r / 2) % MOD;
}

signed main(void){
    ll n, a, b;
    cin >> n >> a >> b;
    COMinit();
    
    ll ans = loop_sq(2, n) - 1LL;
    ll nCa = 1LL, nCb = 1LL;
    
    rep(i,a) nCa = nCa * (n - i) % MOD;
    nCa = nCa * finv[a] % MOD;
    rep(i,b) nCb = nCb * (n - i) % MOD;
    nCb = nCb * finv[b] % MOD;
    
    cout << ((ans - nCa + MOD) % MOD - nCb + MOD) % MOD  << endl;
    return 0;
}


Measured memory_bytes: 16000
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;


int main()
{
    int n,m,i,k,l,j;
    scanf("%d %d",&n,&m);
    if(n<=0&&m>=0)
        printf("Zero\n");
    else if(n>0)
        printf("Positive\n");
    else
    {
        k=m-n;
        if(k%2==0)
            printf("Negative\n");
        else
            printf("Positive\n");
    }
    return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn main() {
    let l: usize = read();
    let r: usize = read();
    let l2 = l / 2019;
    let r2 = r / 2019;
    if l2 < r2 || l % 2019 == 0 || r % 2019 == 0 {
        println!("{}", 0);
    } else {
        let l = l % 2019;
        let r = r % 2019;
        let mut min = 2019*2019;
        for i in l..r+1 {
            for j in i+1..r+1 {
                min = std::cmp::min(min, (i*j)%2019);
            }
        }
        println!("{}", min);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
/*#include <iostream>
int main()
{
    long long n;
    scanf("%d", &n);
}*/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> p(n);
    for (auto& i : p) scanf("%d", &i);
    sort(p.begin(), p.end());
    int r = 0;
    for (int i = 0; i < k; i++)
    {
        r += p[i];
    }
    printf("%d\n", r);
    return 0;
}

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

int main()
{
int n;
cin>>n;
long long arr[n];long long ans=1e9;
for(int i=0;i<n;i++)
    cin>>arr[i];
for(int i=0;i<100;i++)
{
     long long sum=0;
    for(int j=0;j<n;j++)
    {
        sum+=(arr[j]-i)*(arr[j]-i);
    }
    if(sum<ans)
        ans=sum;
}
cout<<ans;
}


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

int main()
{
	int n, k, max = 0, pcon = 0, p = 0, start = 0, p1 = 0, tr = 0;
	cin >> n >> k;
	string s;
	cin >> s;
	char cy;
	cy = s[0];
	for (auto c : s)
	{

		if (pcon != 0) {
			if (cy != c && max == 0) {
				max = 1;
			}
			else if (max == 1 && cy != c) {
				p += 1;
				max = 0;
			}
			cy = c;
		}
		pcon = 1;
	}
	if (s[0] != s[n - 1]) {
		p1 = 1;
	}
	while (k > 0 && p > 0) {
		start += 2;
		k -= 1;
		p -= 1;
	}
	while (k > 0 && p1 > 0) {
		start += 1;
		k -= 1;
		p1 -= 1;
	}
	pcon = 0;
	cy = s[0];
	for (auto c : s)
	{

		if (pcon != 0) {
			if (cy == c) {
				tr += 1;
			}
			cy = c;
		}
		pcon = 1;
	}
	cout << start + tr;
}


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

class Atcoder98
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int[] card = input.Select(int.Parse).ToArray();

        Array.Sort(card);

        Console.WriteLine(card[2] * 10 + card[1] + card[0]);
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n;
	cin >> n;
	int isp[55556] = {};
	int i, j; isp[0] = 1; isp[1] = 1;
	for (i = 2; i < 55556; i++) {
		if (isp[i] == 0) {
			for (j = 2 * i; j < 55556; j += i) {
				isp[j] = 1;
			}
		}
	}
	vector<int>s;
	for (i = 0; i < 55556; i++) {
		if (isp[i] == 0 && i % 5 == 1)s.push_back(i);
	}
	for (i = 0; i < n; i++) {
		cout << s[i] << " ";
	}
	cout << endl;
	char nyaa;
	cin >> nyaa;
	return 0;
}

Measured memory_bytes: 512
import math


def find_root(ele):
    root = node_list[ele]['root']
    if root is not None:
        return find_root(root)
    return ele


N, M = list(map(int, input().split()))
bridge_list = list()
for _ in range(M):
    bridge_list.append(list(map(int, input().split())))

answer_list = [math.factorial(N) // math.factorial(2) // math.factorial(N - 2)]
node_list = [{'root': None, 'child_count': 0} for i in range(N)]

for bridge_list in bridge_list[:0:-1]:
    a = bridge_list[0] - 1
    b = bridge_list[1] - 1
    a_root = find_root(a)
    b_root = find_root(b)
    if a_root != b_root:
        answer_list.append(answer_list[-1] - (node_list[a_root]['child_count'] + 1) * (node_list[b_root]['child_count'] + 1))
        next_root = min(a_root, b_root)
        old_root = max(a_root, b_root)
        node_list[next_root]['child_count'] += node_list[old_root]['child_count'] + 1
        node_list[old_root]['root'] = next_root
    else:
        answer_list.append(answer_list[-1])

for answer in answer_list[::-1]:
    print(answer)


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;


int main() {

    int n;
    cin >> n;

    int ans = 0;
    fo(i, n) {
        int a;
        cin >> a;
        while ( !(a & 1) ) {
            a /= 2;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
#  A,B = map(int, input().split())
  A = int(input())
  B = int(input())
  C = int(input())
  X = int(input())
  
  count = 0
  
  for a in range(A+1):
    for b in range(B+1):
      for c in range(C+1):
        if X == 500*a + 100*b + 50*c:
          count += 1
  print(count)
          
if __name__ == "__main__":
  main()
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main() {

string S ;
cin >> S ;
int A=S.size() ;
  int ans = 1000 ;
rep(i,A-2){
  int B = ctoi(S.at(i));
  int C = ctoi(S.at(i+1));
  int D = ctoi(S.at(i+2));
  //cout << B*100+C*10+D<<endl;
  ans = min(ans,abs(753-(B*100+C*10+D))) ;
}
  cout << ans ;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    _n: usize,
    s: chars,
    q: usize,
    query: [usize; q],
  }
  for &k in &query {
    let mut ans = 0i64;
    let mut d = 0;
    let mut m = 0;
    let mut dm = 0;
    for (i, &c) in s.iter().enumerate() {
      if let Some(out) = i.checked_sub(k) {
        match s[out] {
          'D' => {
            d -= 1;
            dm -= m;
          },
          'M' => {
            m -= 1;
          }
          _ => (),
        }
      }
      match c {
        'D' => {
          d += 1;
        },
        'M' => {
          m += 1;
          dm += d;
        },
        'C' => {
          ans += dm;
        },
        _ => (),
      }
    }
    puts!("{}\n", ans);
  }
}


Measured memory_bytes: 13560
array = gets.chomp.split('')
Q = gets.chomp.to_i

flag = true

Q.times do
  q = gets.chomp.split(' ')
  if q.size == 1
    flag = !flag
  else
    if q[1] == '2'
      if flag
        array.push(q[2])
      else
        array.unshift(q[2])
      end
    else
      if flag
        array.unshift(q[2])
      else
        array.push(q[2])
      end
    end
  end
end

puts flag ? array.join : array.reverse.join


Measured memory_bytes: 30844
x = []
y = []

while True:
    x1, y1 = map(int, input().split())
    if x1 == 0 and y1 == 0:
        break
    else:
        x.append(x1)
        y.append(y1)

iterations = len(x)

for i in range(iterations):
    print(min(x[i], y[i]), max(x[i], y[i]))


Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define rep3(i, s, n) for (int i = (s); i <=(int) (n); i++)
#define chmax(x,y) x = max(x,y)

	int a[3005][3005];
	long long dp[3005][3005][5];


int main() {
	int R,C,n;
	cin >> R >> C >> n;

	rep(i, n) {
	int r,c,v;
		cin >> r >> c >> v;
		a[r-1][c-1]=v;
	}

	rep(i,R){
 		rep(j,C) {
			for (int k=2;k>=0; k--){
				chmax(dp[i][j][k+1],dp[i][j][k]+a[i][j]);
			}
			rep(k,4) {
				chmax(dp[i+1][j][0],dp[i][j][k]);
				chmax(dp[i][j+1][k],dp[i][j][k]);
			}
			
		}
	}
	long long ans =0;
	rep(k,4) chmax(ans,dp[R-1][C-1][k]);

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


Measured memory_bytes: 391060
a,b = map(int, input().split())
grA = [1,3,5,7,8,10,12]
grB = [4,6,9,11]
grC = [2]
if (a in grA and b in grA) or (a in grB and b in grB):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl

int main(){
	int  a, b; cin>>a>>b;
	for(int i = max(a, b); i <= 100000; i++){
		int left = trunc(i * 0.08);
		int right = trunc(i * 0.1);
		if(left == a && right == b){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n , m;
   cin >> n >> m;
   vector<int> a(n);
   priority_queue<int> pq;
   for(int &x : a)
      cin >> x , pq.push(x);

   for(int i = 0 ; i < m ; ++i){
      if(pq.empty())break;
      int top = pq.top();pq.pop();
      top /= 2;
      if(top)pq.push(top);
   }

   long long sum = 0;
   while (pq.size()){
      int top = pq.top();pq.pop();
      sum += top;
   }

   cout << sum << "\n";
}

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

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(i!=s.size()-2){
			if(s[i]==s[i+2]){
				cout<<i+1<<' '<<i+3<<endl;
				return 0;
			}
		}
		if(s[i]==s[i+1]){
			cout<<i+1<<' '<<i+2<<endl;
			return 0;
		}
	}
	cout<<-1<<' '<<-1<<endl;
	return 0;
}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl



signed main(){

	int N, K;
	string S;
	cin >> N >> K;
	cin >> S;

	// 連続する長さを数えてpairに		{1,2,1,1,3,2,2}=>{(1,1),(2,1),(1,2),(3,1),(2,2)}
	vector<pair<char,int>> v;
	rep(i, N){
		int q = i;
		while (q < N && S[i] == S[q]) q++;
		v.push_back(P(S[i], q - i));
		i = q-1;
	}

	vector<int> s(v.size()+1);	// 累積和 
	rep(i, v.size() + 1) s[i] = 0;
	for (int i = 0; i < v.size(); i++){
		s[i + 1] = s[i] + v[i].second;
	}

	int ans = -INF;
	rep(i, v.size()){
		int tmp;
		if (v[i].first == '1'){
			tmp = s[min((int)v.size(),i + 2 * K + 1)] - s[i];
		}
		else{
			tmp = s[min((int)v.size(), i + 2 * K)] - s[i];
		}
		ans = max(ans, tmp);
	}

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

Measured memory_bytes: 2800
#include <iostream>
#include <iomanip>  //std::cout<<fixed や std::cout<<setprecision() を使うための
using namespace std;
int main(int argc, const char * argv[]) {
    int a,b;
    cin >> a >> b;
    cout << fixed;  //小数点の桁数を正確に指定(%fに相当)
    cout<< setprecision(5); //()で桁数を指定
    cout << a/b <<" "<< a%b <<" "<<(double)a/b << endl;
    return 0;
}


Measured memory_bytes: 3280
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int P = int.Parse(input[1]);
        Console.WriteLine((3 * A + P) / 2);
    }
 }

Measured memory_bytes: 13140
n, m = map(int, input().split())

minmax = 0
maxmin = 100000

for i in range(m):
    l, r = map(int, input().split())
    if l > minmax:
        minmax = l

    if r < maxmin:
        maxmin = r

if maxmin - minmax + 1 > 0:
    print(maxmin - minmax + 1)
else:
    print("0")



        


    







        



Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

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

  for (int i = 0; ; ++i)
    if (111*i >= N) {
      out(111*i);
      break;
    }

  return 0;
}


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

int main(void) {
    int N,T;cin>>N>>T;
    int cnt = 0;
    int cost_min = 10000;
    for (int i = 0; i < N; i++) {
        int c,t;cin>>c>>t;
        if (t <= T) {
            if (cost_min > c) cost_min = c;
            cnt++;
        }
    }
    if (cnt > 0) cout << cost_min << endl;
    else cout << "TLE" << endl;
    return 0;
}

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

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  int ls = s.length(), lt = t.length();
  int dp[ls+1][lt+1];
  rep(i, ls+1){
    rep(j, lt+1) dp[i][j] = 0;
  }
  rep(i, ls){
    rep(j, lt){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
      } else {
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
      }
    }
  }
  string ans = "";
  int i = ls, j = lt;
  while(i > 0 && j > 0){
    if(dp[i][j] == dp[i-1][j]) i--;
    else if(dp[i][j] == dp[i][j-1]) j--;
    else {
      ans = s[i-1] + ans;
      i--, j--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  if (a % 2 != b % 2) cout << "IMPOSSIBLE" << endl;
  else cout << (a + b) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
// Problem : A - Range Flip Find Route
// Contest : AtCoder - AtCoder Grand Contest 043
// URL : https://atcoder.jp/contests/agc043/tasks/agc043_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
    return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
    mem(isprime,true);
    for(ll p=2;p*p<=n;p++)
    {
        if(isprime[p]==true)
        {
            for(ll i=p*p;i<=n;i+=p)
                isprime[i]=false;
        }
    }
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    char a[n][m];
    ll dp[n][m];
    rep(i,0,n)
    {
    	rep(j,0,m)
    	{
    		cin>>a[i][j];
    		dp[i][j]=INF;
    	}
    }
    if(a[0][0]=='#')
    	dp[0][0]=1;
    else
    	dp[0][0]=0;
    ll x,y;
    ll p[2]={1,0};
    ll q[2]={0,1};
    rep(i,0,n)
    {
    	rep(j,0,m)
    	{
    		rep(k,0,2)
    		{
	    		x=i+p[k];
	    		y=j+q[k];
	    		if(x>=n or y>=m)
	    			continue;
	    		ll add=0;
	    		if(a[i][j]=='.' and a[x][y]=='#')
	    			add=1;
	    		dp[x][y]=min(dp[i][j]+add,dp[x][y]);
    		}
    	}
    }
    cout<<dp[n-1][m-1];
}
int main()
{
    ll inpoup = 0;
    if(inpoup==1)
    {
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    IOS
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = s[0];
        int X = s[1];
        int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
        List<int> d = new List<int>();
        for (int i = 0; i < n; i ++) {
            d.Add(Math.Max(x[i],X) - Math.Min(x[i],X));
          d.Distinct();
        }
        int result = d[0];
        for(int i = 1; i < d.Count(); i ++) {
            result = gcd(result, d[i]);
        }
        Console.WriteLine(result);
    }
    public static int gcd(int a, int b) {
        if (a < b) return gcd(b,a);
        while (b != 0) {
             var remainder = a % b;
             a = b;
             b = remainder;
         }
         return a;
    }
}

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

using namespace std;

const int INF = 1 << 29;

int main()
{
  int N, M, R, r[8];
  int G[200][200];

  fill_n(*G, 200 * 200, INF);
  for(int i = 0; i < 200; i++) G[i][i] = 0;

  cin >> N >> M >> R;
  for(int i = 0; i < R; i++) {
    cin >> r[i];
    --r[i];
  }
  for(int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    --x, --y;
    G[x][y] = G[y][x] = z;
  }

  for(int k = 0; k < N; k++) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }

  vector< vector< int > > dp(1 << R, vector< int >(R, INF));
  for(int i = 0; i < R; i++) dp[1 << i][i] = 0;


  for(int i = 0; i < 1 << R; i++) {
    for(int j = 0; j < R; j++) {
      for(int k = 0; k < R; k++) {
        dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + G[r[j]][r[k]]);
      }
    }
  }

  int ret = INF;
  for(int i = 0; i < R; i++) {
    ret = min(ret, dp[(1 << R) - 1][i]);
  }
  cout << ret << endl;
}

Measured memory_bytes: 384
#include <cstdio>

using namespace std;

int main()
{
    int n, sum=0, num;

    scanf("%d",&n);

    for(int i=1; i<=n; i++)
    {
        scanf("%d", &num);
        sum += num-1;
    }

    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;

int main(void) {
    ll N, M;
    cin >> N >> M;
    ll i;
    ll cnt[50]={0};
    ll a, b;
    for(i=0; i<M; i++) {
        cin >> a >> b;
        a--; b--;
        cnt[a]++;
        cnt[b]++;
    }
    
    for(i=0; i<N; i++)
        cout << cnt[i] << endl;
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, p1, p2, x;
            var word = Console.ReadLine().Split(' ');
            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);
            p1 = n * a;
            p2 = b;
            if (p1 < p2)
                x = p1;
            else
                x = p2;            
            Console.WriteLine(x);
            Console.ReadKey(); 
        }
    }
}


Measured memory_bytes: 13140
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	private static final String DIV_RGX = "(\\+|=)";

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in).useDelimiter(System.getProperty("line.separator"));

    	String   s;
    	int      ans;
    	BigInteger[] num = new BigInteger[3];
    	while(sc.hasNext()){
    		s = sc.next();
    		ans = -1;
    		for(int i = head_check(s);i<10;i++){
    			num = chg(s,i);
    			if((num[0].add(num[1])).equals(num[2])){
    				ans = i;
    			}
    		}
    		if   (ans != -1){System.out.println(ans); }
    		else            {System.out.println("NA");}
    	}
	}

    private static int head_check(String s){
		String[] s_ar = s.split(DIV_RGX);
    	int ret = 0;
    	for(String s_:s_ar){
    		if(s_.charAt(0) == 'X' && s_.length() != 1){
    			ret = 1;
    		}
    	}
    	return ret;
    }

    private static BigInteger[] chg(String s,int r){
    	BigInteger[] ret = new BigInteger[3];
    	s = s.replace('X',String.valueOf(r).charAt(0));
		String[] s_ar = s.split(DIV_RGX);
		for(int i=0;i<3;i++){
			ret[i] = new BigInteger(s_ar[i]);
		}
		return ret;
    }
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename T >
int64_t largest_rectangle(vector< T > height) {
  stack< int > st;
  height.push_back(0);
  vector< int > left(height.size());
  int64_t ret = 0;
  for(int i = 0; i < height.size(); i++) {
    while(!st.empty() && height[st.top()] >= height[i]) {
      ret = max(ret, (int64_t) (i - left[st.top()] - 1) * height[st.top()]);
      st.pop();
    }
    left[i] = st.empty() ? -1 : st.top();
    st.emplace(i);
  }
  return (ret);
}

int main() {
  int H, W;
  cin >> H >> W;
  auto mat = make_v< int >(H, W);
  cin >> mat;

  vector< int > last(W, -1);
  int ret = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(mat[i][j] == 1) last[j] = i;
    }
    vector< int > dp(W);
    for(int j = 0; j < W; j++) {
      dp[j] = i - last[j];
    }
    chmax(ret, largest_rectangle(dp));
  }
  cout << ret << endl;
}




Measured memory_bytes: 10352