akhauriyash/Code-Regression huggingface dataset:
n=int(input())

for i in range(n):
  a,b=[int(i) for i in input().split()]
  if a==b:
    print((min(a,b)-1)*2)
  else:
    if int((a*b)**0.5) * (int((a*b)**0.5)+1) < a*b:
      print(int((a*b)**0.5) *2 - 1)
    elif int((a*b)**0.5) **2 == a*b:
      print(int((a*b)**0.5) *2 - 3)
    else:
      print(int((a*b)**0.5) *2 -2)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, d;
    cin >> n >> d;
    const ll N = n;
    const ll D = d;
    ll a[N][D];
    ll sum;

    for(ll i = 0; i < N; i++)
    {
        for(ll j = 0; j < D; j++)
        {
            cin >> a[i][j];
        }
    }
    ll cnt = 0;
    for(ll i = 0; i < N; i++)
    {
        for(ll j = i+1; j < N; j++)
        {
             sum = 0;
            for(ll k = 0; k < D; k++)
            {
                sum +=   abs ( a[i][k] - a[j][k] )  *   abs ( a[i][k] - a[j][k] ) ;
            }

            for(ll p = 0; p*p <= sum; p++)
            {
                if(p*p == sum)
                {
                    cnt++;
                }
            }




        }
    }
    cout << cnt;


}



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

int main(){
  string n;
  cin>>n;
  
  
  long long sum=0;
  for(long long i=0;i<n.size();i++){
    int digit=n.at(i)-'0';
    sum+=digit;
  }
  
  if(sum%9==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3752
N, X = map(int,input().split())
A = map(int,input().split())

s = 0

def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a%b)

for i in A:
  s = gcd(abs(X-i), s)
  
print(s)
  

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

#define F first    
#define S second
#define mp make_pair
#define pii pair<int,int>         
// mikty prikoldar
#define ll long long  
#define pb push_back
#define sz(a) (int)(a.size())
#define Accepted 0
#define endl '\n'
//everything goes according to the plan
#define y1 		 NOT
#define left   NEEDED
#define right  THINGS  
//countdown BEGAN. 10 , 9 , 8 ...
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4611686018427387903;
const int Sz = 1110111;
// ai dyn dyn dyn dirindai ai dyn dyn dirindai
using namespace std;
// skr skr skr v chernih naikah
inline void Read_rap () {	// smoke weed everyday
  ios_base :: sync_with_stdio(0);
	cin.tie(0);      
}              
int t[Sz];

int a[Sz];

int n;
           
inline void build (int v, int tl, int tr) {
	if (tl == tr) {
		t[v] = a[tl];
		return;
	}
	int tmid = (tl+tr) >> 1;
	build (2*v, tl, tmid);
	build (2*v+1, tmid+1, tr);
            
  int x = t[2*v], y = t[2*v+1];
  t[v] = max(x, y) - min (x, y);
  if (t[v] == 0)	t[v] = x;
}
       
int main() 
{
	Read_rap ();
	cin >> n;
	
	n = (1<<n);
	for (int i = 1;i <= n;i ++)	cin >> a[i];

	build (1, 1, n);

	cout << t[1];

	return Accepted;
}	









// Coded by Z...

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long llong;

static const int INF = 10e9 + 1;

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

    int A[n];
    int x;
    int cnt = 0;
    int minx = INF;
    int find = 0;
    for (int i = 0; i < n; i++){
        scanf("%d", &x);
        if (x < 0) cnt++;
        if (x == 0) find = 1;
        if (minx > abs(x)) minx = abs(x);
        A[i] = x;
    }

    llong ans = 0;
    if (cnt % 2 == 0 || find == 1){
        for (int i = 0; i < n; i++){
            if (A[i] < 0) ans += A[i] * -1;
            else ans += A[i];
        }
    }else{
        for (int i = 0; i < n; i++){
            if (abs(A[i]) == minx) ans -= abs(A[i]);
            else if (A[i] < 0) ans += A[i] * -1;
            else ans += A[i];
        }
    }

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

Measured memory_bytes: 640
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int N=2005;
///Code begin..................................................................
inline LL Scan() {
    LL x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

VI v;

int main()
{
    int n, x;
    scanf("%d",&n);
    FOR(i,1,n) scanf("%d",&x), v.pb(x);
    sort(v.begin(),v.end());
    int siz=unique(v.begin(),v.end())-v.begin();
    printf("%d\n",siz);
    return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder{
  class Program{
    static void Main(string[] args){
      int n = int.Parse(Console.ReadLine());
      string[] input = Console.ReadLine().Split(' ');
      Int64[] dp = new Int64[n];
      dp[0] = 0;
      dp[1] = Math.Abs(int.Parse(input[0]) - int.Parse(input[1]));
      for(int i = 2; i < n; i++){
        int a = int.Parse(input[i]);
        int b = int.Parse(input[i-1]);
        int c = int.Parse(input[i-2]);
        dp[i] = Math.Min(dp[i-2] + Math.Abs(a-c), dp[i-1] + Math.Abs(a-b));
      }
      Console.WriteLine(dp[n-1]);
    }
  }
}


Measured memory_bytes: 35072
#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>;
const int MOD=1000000007;

int main() {
  int n;
  cin >> n;
  map<int,int> a, b;
  rep(i,n/2) {
    int x, y;
    cin >> x >> y;
    a[x]++; b[y]++;
  }
  int maxa=0, maxb=0;
  int maxa2=0, maxb2=0;
  int A, B;
  for(auto p: a) {
    if(maxa<p.second) {
      maxa=p.second;
      A=p.first;
    }
  }
  for(auto p: a) {
    if(p.first==A) continue;
    maxa2=max(maxa2,p.second);
  }
  for(auto p: b) {
    if(maxb<p.second) {
      maxb=p.second;
      B=p.first;
    }
  }
  for(auto p: b) {
    if(p.first==B) continue;
    maxb2=max(maxb2,p.second);
  }

  int ans=n-maxa-maxb;
  if(A==B) ans=min(n-maxa-maxb2,n-maxa2-maxb);
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include<stdio.h>

int main(void){
    int n,m,c;
    int d = 0;
    int h = 0;
    int sum = 0;
    scanf("%d %d %d", &n, &m, &c);
    int b[m];
    int a[n][m];
    for(int i=0;i<m;i++){
        scanf("%d", &b[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(int i=0;i<n;i++){
        sum = 0;
        for(int j=0;j<m;j++){
            sum += a[i][j] * b[j];
            if(j == m-1){
                sum += c;
                if(sum > 0){
                    h++;
                }
            }
        }
    }
    printf("%d\n", h);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
  	int n,a[200],sum1=0,sum2=0;
  	cin>>n;
  	for(int i=0;i<n;i++) cin>>a[i];
  	for(int i=0;i<n-1;i++)
  		for(int j=i+1;j<n;j++)
  			if(a[i]<a[j]) swap(a[i],a[j]);
  	for(int i=0;i<n;i++)
  		if(i%2) sum2+=a[i];
  		else sum1+=a[i];
  	cout<<sum1-sum2<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
//const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

//below here

int main(){
	int n;
	cin >> n;
	if(n&1){
		cout << "No" << endl;
		return 0;
	}
	string s;
	cin >> s;
	if(s.substr(0,n/2)==s.substr(n/2,n/2)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int a, b;
  	cin >> a >> b;
  	if(max(a,b)>8) puts(":(");
  	else puts("Yay!");
    return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=0;cin>>n;
  vector<int>l(n);
  for(int i=0;i<n;i++){
    cin>>l.at(i);
    a+=l.at(i);
  }
  sort(l.begin(),l.end());
  if(a-l.at(n-1)>l.at(n-1))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define iPair pair<int, int>
#define iiPair pair<int, pair <int, int >>
#define For(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
iPair x[100001], y[100001];
struct Graph{
    int V, E;
    vector<iiPair> e;
    Graph(int V, int E){
        this -> V = V;
        this -> E = E;
    }
    void addEdge(int a, int b, int w) {
        iPair t = make_pair(a, b);
        e.push_back(make_pair(w, t));
        E++;
    }
    int kruskal();
};
struct DisjoinSet{
    int *par, *rank;
    int n;
    DisjoinSet(int n){
        this -> n = n;
        par = new int[n + 1];
        rank = new int[n + 1];
        For(i, 1, n) {
            rank[i] = 0;
            par[i] = i;
        }
    }
    int find(int i){
        while(par[i] != i) i = par[i];
        return i;
    }
    void Union(int x, int y){
        x = find(x);
        y = find(y);
        if(rank[x] < rank[y]) par[x] = y;
        else par[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }
    
};
int Graph::kruskal(){
    int mst_tw = 0;
    DisjoinSet ds(V);
    vector<iiPair>::iterator it;
    sort(e.begin(), e.end());
    for(it = e.begin(); it != e.end(); ++it){
        int u = it->second.first;
        int v = it->second.second;
        if(ds.find(u) != ds.find(v)){
            ds.Union(u, v);
            mst_tw += it -> first;
        }
    }
    return mst_tw;
}
int main(){
    int V;
    cin >> V;
    Graph g(V, 0);
    For(i, 1, V){
        int a, b;
        cin >> a >> b;
        x[i] = make_pair(a, i);
        y[i] = make_pair(b, i);
    }
    sort(x + 1, x + 1 + V);
    sort(y + 1, y + 1 + V);
    For(i, 1, V - 1){
        g.addEdge(x[i + 1].second, x[i].second, x[i + 1].first - x[i].first);
        g.addEdge(y[i + 1].second, y[i].second, y[i + 1].first - y[i].first);
    }
    cout << g.kruskal() << endl;
    return 0;
}


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

int main()
{
    int x,y;
    cin>>x>>y;
       while(!(x==0&&y==0)){
        if(x<y){
            cout<<x<<" "<<y<<endl;
        }else{
            cout<<y<<" "<<x<<endl;
        }
        cin>>x>>y;
    }
    return 0;
}


Measured memory_bytes: 2980
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

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

    if(n < 10) {
        cout << n << endl;
    } else if(n < 100) {
        cout << 9 << endl;
    } else if(n < 1000) {
        cout << 9 + (n - 99) << endl;
    } else if(n < 10000) {
        cout << 909 << endl;
    } else if(n < 100000) {
        cout << 909 + (n - 9999) << endl;
    } else {
        cout << 90909 << endl;
    }
}

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

long lcm(long a, long b) {
  long tmp = 0;
  long r = 0;
  long x = a * b;
  if(a < b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  return x / b;
}

int main() {
  long a, b, c, d;
  cin >> a >> b >> c >> d;
  long e = lcm(c, d);
  //cout << e << endl;
  long num = b - a + 1;
  long num_c = 0;
  long num_d = 0;
  long num_e = 0;
  
  if(a % c == 0) {
    num_c = b/c - a/c + 1;
  } else {
    num_c = b/c - a/c;
  }
  if(a % d == 0) {
    num_d = b/d - a/d + 1;
  } else {
    num_d = b/d - a/d;
  }
  if(a % e == 0) {
    num_e = b/e - a/e + 1;
  } else {
    num_e = b/e - a/e;
  }
  //cout << num_c << num_d << num_e << endl;
  cout << num - (num_c + num_d - num_e) << endl;
}


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

#define _For(idx, from, to, inc, cmp) \
	for(auto idx=(from) ; idx cmp (to) ; inc idx)
#define ForLE(idx, from, to) \
	_For(idx, from, to, ++, <=)
#define ForGE(idx, from, to) \
	_For(idx, from, to, --, >=)
#define ForLT(idx, from, to) \
	_For(idx, from, to, ++, <)
#define ForGT(idx, from, to) \
	_For(idx, from, to, --, >)
#define For(idx, from, to) \
	_For(idx, from, to, ++, <)

using u64 = uint64_t;
u64 MakePair(const int from, const int to) {
	return (u64(from) << 32) | to;
}
#include <unordered_set>
#include <algorithm>
int main() {
	int NLand,
		NEdge;
	std::cin >> NLand >> NEdge;
	std::vector<int> beg,
					dst;
	For(i, 0, NEdge) {
		int e0, e1;
		std::cin >> e0 >> e1;
		if(e0 > e1)
			std::swap(e0, e1);
		if(e0 == 1)
			beg.push_back(e1);
		else if(e1 == NLand)
			dst.push_back(e0);
	}
	std::sort(dst.begin(), dst.end());
	const auto chk = [&](){
		for(auto inter : beg) {
			const auto itr = std::lower_bound(dst.begin(), dst.end(), inter);
			if(itr != dst.end() && *itr == inter)
				return true;
		}
		return false;
	};
	if(chk())
		std::cout << "POSSIBLE";
	else
		std::cout << "IMPOSSIBLE";
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 1276
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	int ans = 0;
	if(x * 2 == w && y * 2 == h) ans = 1;
	cout << fixed << setprecision(10) <<  0.5 * w * h << " ";
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#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>;
int main() {
    int n; cin >> n;
    vector<int> cnt(4, 0);
    rep(i, n) {
        string s; cin >> s;
        if (s == "AC") cnt[0]++;
        else if(s == "WA") cnt[1]++;
        else if(s == "TLE") cnt [2]++;
        else cnt[3]++;
    }

    printf("AC x %d\n", cnt[0]);
    printf("WA x %d\n", cnt[1]);
    printf("TLE x %d\n", cnt[2]);
    printf("RE x %d\n", cnt[3]);
}


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

int main() {
	cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int h, r;
	cin >> h >> r;
	int x = h + r;
	if (x == 0) {
		cout << 0 << endl;
	} else if (x > 0) {
		cout << 1 << endl;
	} else {
		cout << -1 << endl;
	}
}


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

int main(){
  int height,width;
  cin >> height >> width;     
  vector<vector<char>> picture(height + 2,vector<char>(width + 2,'#'));
  
  for(int i = 1; i <= height; i++)
    for(int r = 1; r <= width; r++){
      cin >> picture.at(i).at(r);
    }
  
  for(int i = 0; i < picture.size(); i++){
    for(int r = 0; r < picture.at(0).size(); r++){
      cout << picture.at(i).at(r);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        for(int i = 0; i < s.length(); i++){
            char c = s.charAt(i);
            if(c != '1'){
                System.out.println(c);
                return;
            }
            if((long)i+1 == k){
                break;
            }
        }
        System.out.println(1);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    LL ans = 0;
    LL tmp = 0;
    rep(i, n){
        if(s[i] == 'A') tmp++;
        else{
            if(i+1 >= n) break;
            if(s[i] == 'B' && s[i+1] == 'C'){
                ans += tmp;
                i++;
            }else{
                tmp = 0;
            }
        }
    }
    cout << ans << endl;



}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
	int a, b = 100000, i;
	double c;
	scanf("%d", &a);
	for(i = 0; i < a; i++){
		b *= 1.05;
		if(b % 1000 > 0){
			c = b / 1000;
			c++;
			b = c * 1000;
		}
	}
	printf("%d\n", b);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define RST(a) memset(a, 0, sizeof(a))
#define RSTV(a, v) memset(a, v, sizeof(a))
#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
const int INF = 0x3f3f3f3f, qhqh = 1000000007;
ll a[100000], d[100000];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  d[0] = 0;
  FOR(i, 0, n) cin >> a[i];
  FOR(i, 0, n) d[0] += a[i] * pow(-1, i);
  FOR(i, 1, n) d[i] = 2 * a[i - 1] - d[i - 1];
  FOR(i, 0, n) cout << d[i] << ' ';
}


Measured memory_bytes: 2944
N, K, *A = map(int, open(0).read().split()) 

f = [0]*N

l = 1
ff = 0
f[l-1] = K
while K > 0:
  l = A[l-1]
  K -= 1
  if f[l-1] != 0:
    K = K % (f[l-1]-K)
    break
  f[l-1] = K
#
while K > 0:
  l = A[l-1]
  K -= 1
#
print(l)


Measured memory_bytes: 31776
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

static const int dx4[]={-1, 0, 1, 0}, dy4[]={0, -1, 0, 1};
static const int dx8[]={-1, -1, -1, 0, 0, 1, 1, 1};
static const int dy8[]={-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    vector<vector<int>> g(10, vector<int>(10));

    while (true) {
        size_t x, y;
        int s;
        if (scanf("%zu, %zu, %d", &x, &y, &s) == EOF)
            break;

        ++g[y][x];
        if (s == 1) {
            for (size_t k=0; k<4; ++k) {
                int X=x+dx4[k], Y=y+dy4[k];
                if (!(0<=X && X<10 && 0<=Y && Y<10))
                    continue;

                ++g[Y][X];
            }
        } else if (s == 2) {
            for (size_t k=0; k<8; ++k) {
                int X=x+dx8[k], Y=y+dy8[k];
                if (!(0<=X && X<10 && 0<=Y && Y<10))
                    continue;

                ++g[Y][X];
            }
        } else if (s == 3) {
            for (size_t k=0; k<8; ++k) {
                int X=x+dx8[k], Y=y+dy8[k];
                if (!(0<=X && X<10 && 0<=Y && Y<10))
                    continue;

                ++g[Y][X];
            }
            for (size_t k=0; k<4; ++k) {
                int X=x+2*dx4[k], Y=y+2*dy4[k];
                if (!(0<=X && X<10 && 0<=Y && Y<10))
                    continue;

                ++g[Y][X];
            }
        }
    }

    pair<size_t, int> res;  // <0, max>
    for (vector<int> &col: g)
        for (int d: col) {
            if (d == 0)
                ++res.first;

            if (res.second < d)
                res.second = d;
        }

    printf("%zu\n", res.first);
    printf("%d\n", res.second);
    return 0;
}
                

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, T;
    cin >> N >> T;

    ll ans = INF;

    REP(i, N){
        ll c, t;
        cin >> c >> t;
        if(t <= T){
            ans = min(ans, c);
        }
    }
    if(ans == INF){
        cout << "TLE" << endl;
    }
    else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long d = sc.nextInt();
		int ans = 0;

		for(int i=0; i<n; i++) {
			long x = sc.nextInt();
			long y = sc.nextInt();

			if( x*x+y*y <= d*d ) {
				ans++;
			}

		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 60548
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Array.Unboxed

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,c] <- getIntList
    ds <- array ((1,1),(c,c)) . zip [(i,j)|i<-[1..c],j<-[1..c]] . concat <$> replicateM c getIntList :: IO(UArray (Int,Int) Int)
    cs <- array ((1,1),(n,n)) . zip [(i,j)|i<-[1..n],j<-[1..n]] . concat <$> replicateM n getIntList :: IO(UArray (Int,Int) Int)

    v0 <- VUM.replicate c (0 :: Int)
    v1 <- VUM.replicate c (0 :: Int)
    v2 <- VUM.replicate c (0 :: Int)
    forM_ [1..n] $ \i -> do
        forM_ [1..n] $ \j -> do
            let a = (i+j) `mod` 3
            let cij = (cs ! (i,j)) - 1
            when (a == 0) $ VUM.modify v0 succ cij
            when (a == 1) $ VUM.modify v1 succ cij
            when (a == 2) $ VUM.modify v2 succ cij
    fv0 <- VU.unsafeFreeze v0
    fv1 <- VU.unsafeFreeze v1
    fv2 <- VU.unsafeFreeze v2

    let colors = [(c0,c1,c2)| c0 <- [0..c-1], c1 <-[0..c-1], c2 <- [0..c-1], c0 /= c1, c1 /= c2, c2 /= c0]
    let ans = minimum $ map f colors
            where f (c0,c1,c2) = s0 + s1 + s2
                      where s0 = sum $ map (\ci -> (fv0 VU.! ci) * (ds ! (ci+1,c0+1))) [0..c-1]
                            s1 = sum $ map (\ci -> (fv1 VU.! ci) * (ds ! (ci+1,c1+1))) [0..c-1]
                            s2 = sum $ map (\ci -> (fv2 VU.! ci) * (ds ! (ci+1,c2+1))) [0..c-1]
    print ans

Measured memory_bytes: 11748
/*ITP1_3_B.c*/
#include<stdio.h>
int main(void){
   int a[10000],i,j;
   for(i=1;i>=1;i++){
      scanf("%d",&a[i]);
      if(a[i]==0){
         break;
      }
   }
   for(j=2;j<=i;j++){
      printf("Case %d: %d\n",j-1,a[j-1]);
   }
   return 0;
}

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  pair<int, int> boms[m];
  map<int, int> hs, ws;

  for ( int i = 0; i < m; i++ ) {
    int hi, wi;
    cin >> hi >> wi;
    boms[i] = make_pair(hi, wi);
    hs[hi]++;
    ws[wi]++;
  }

  // 行・列における破壊対象の最大数
  int max_h = 0;
  int max_w = 0;
  for ( auto ph : hs ) { if ( ph.second > max_h ) { max_h = ph.second; } }
  for ( auto pw : ws ) { if ( pw.second > max_w ) { max_w = pw.second; } }
  // 破壊対象が最大数の行数・列数
  int max_h_num = 0;
  int max_w_num = 0;
  for ( auto ph : hs ) { if ( ph.second == max_h ) { max_h_num++; } }
  for ( auto pw : ws ) { if ( pw.second == max_w ) { max_w_num++; } }
  // 交差点の組み合わせ総数に対して、交差点に破壊対象がある場合デクリメント
  long long max_set_num = max_h_num * max_w_num;
  for ( int i = 0; i < m; i++ ) {
    if ( hs[boms[i].first] == max_h && ws[boms[i].second] == max_w ) {
      max_set_num--;
    }
  }
  // 全交差点に破壊対象があれば、max_h + max_w -1
  int ans = ( max_set_num != 0 ) ? max_h + max_w : max_h + max_w -1;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 34044
n,m = map(int,input().split())
l = [0]*(m+1) 
for i in range(n):
    A = list(map(int,input().split()))
    for a in A[1:]:
        l[a] += 1
cnt = 0
for d in l:
    if d == n:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 200001;
 
int main(){
    int N;
    int a[MAX];
    int ans[MAX] = {0};

    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> a[i];
    }

    for(int i = N;i > 0;i--){
        int sum = 0;
        for(int j = 1;j * i <= N;j++){
            sum += ans[j * i - 1];
        }
        if(sum % 2 != a[i - 1])ans[i - 1] = 1;
        else ans[i - 1] = 0;
    }

    vector<int> out;
    for(int i = 0;i < N;i++){
        if(ans[i] > 0)out.push_back(i + 1);
    }

    cout << out.size() << endl;
    for(int i = 0;i < out.size();i++){
        cout << (i ? " " : "") << out[i] << endl;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3320
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a,b;
    double f1,f2;
   
    cin >> a >> b ;
    f1 = a;
    f2 = b;

    printf("%d %d %.5f\n",(a/b),(a%b),(f1/f2));
    return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>
int main(void){
int n;
  int a,b;
  int count;
  int total=0;
  scanf("%d",&n);
  for(count=0;count!=n;count++){
  scanf("%d %d",&a,&b);
  total=total+(b-a+1);
  }
  printf("%d",total);
return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

H, W, K = map(int, input().split())

MOD = 1000000007

def solve(H, W, K):
    if W == 1:
        return 1

    # dp = np.zeros((H+1, W), dtype=np.int64)
    dp = [[0 for _ in range(W)] for _ in range(H+1)]
    dp[0][0] = 1

    for h in range(1, H+1):
        # 横線を引ける可能性があるのは2^(W-1)通り
        # 実際は連続した横線は引けないのでもう少し少なくなる
        for i in range(1 << (W-1)):
            # 連続する横線がある場合はスキップ
            ok = True
            for j in range(1, W-1):
                if (i & (1 << j)) and (i & (1 << (j-1))):
                    ok = False
            if not ok:
                continue

            # print("i: ", end="")
            # for j in range(W-1):
            #     print(int(bool(i & (1 << j))), end="")
            # print()
            
            # DP
            # 各縦線についてループ
            for j in range(W):
                # 左側の縦線との間に横線あり
                if j != 0 and i & (1 << (j - 1)):
                    dp[h][j] += dp[h-1][j-1]
                    dp[h][j] %= MOD
                # 右側の縦線との間に横線あり
                elif j != W-1 and i & (1 << j):
                    dp[h][j] += dp[h-1][j+1]
                    dp[h][j] %= MOD
                # 横線なし
                else:
                    dp[h][j] += dp[h-1][j]
                    dp[h][j] %= MOD

    return dp[H][K-1]

print(solve(H, W, K))



Measured memory_bytes: 5552
def main():
    n,m,x=map(int,input().split())
    data=[]
    for i in range(n):
        a=list(map(int,input().split()))
        data.append(a)
    ans=10000000
    for i in range(2**n):
        res=[0]*m
        price=0
        flg=1
        for j in range(n):
            if (i>>j)&1:
                price+=data[j][0]
                for k in range(m):
                    res[k]+=data[j][k+1]
        for j in range(m):
            if res[j]<x:
                flg=0
                break
        if flg==1:
            ans=min(ans,price)
    if ans==10000000:
        print(-1)
    else:
        print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 9236
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007
ll f(ll i) {
	return i*(i-1)/2;
}
void solve(int test_case) {
	int n;
	cin>>n;
	ll cnt = 0;
	unordered_map<string,int> se;
	for(int i=0;i<n;i++) {
		string val;
		cin>>val;
		sort(val.begin(),val.end());
		se[val]++;
	}
	for(auto i:se)if(i.S>1)cnt+=f(i.S);
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 10368
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,m; cin>>m>>n;
    ll ans=0;
    rep(i,m){
        int sub=0;
        rep(j,n){
            int hoge; cin>>hoge;
            if(hoge)sub++;
        }
        cmax(ans,(ll)sub);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3084
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                do{ 
                        long[][] data = new long[4000][2];
                        for(int i = 0 ; i < n ; i++){
                                imput(data, sc.nextInt(), sc.nextInt(), sc.nextInt());
                        }   
                        boolean NA = true;
                        for(int i = 0 ; i < 4000 ; i++){
                                if(data[i][1] >= 1000000){
                                        System.out.println(data[i][0]);
                                        NA = false;
                                }   
                        }   
                        if(NA) System.out.println("NA");
                        n = sc.nextInt();
                }while(n > 0); 
        }   
        static void imput(long[][] source, int num, int sales, int price){
                for(int i = 0 ; i < 4000 ; i++){
                        if(source[i][0] == num){
                                source[i][1] += (long)sales*price;
                                return;
                        }else if(source[i][0] == 0){ 
                                source[i][0] = num;
                                source[i][1] += (long)sales*price;
                                return;
                        }   
                }   
        }   
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  vector<int> hei(317);
  for (int i = 0; i < 317; i++) {
    hei.at(i) = (i+1)*(i+1);
  }
  
  int N;
  if (b < 10){
    N = (a * 10) + b;
  }
  else if (b < 100){
    N = (a * 100) + b;
  }
  else {
    N = (a * 1000) + b;
  }
  
  for (int i = 0; i < 317; i++) {
    if (N == hei.at(i)){
      cout << "Yes" << endl;
      break;
    }
    else if (i == 316){
      cout << "No" << endl;
    }
  }
}

  

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
ac_list = [-Q+K-1 for _ in range(N)]

#正解数＞問題数（Q）-持ちポイント数（K）＋1ならばsurviveできる
for i in A:
  ac_list[i-1] += 1 #各者の正解数

for i in ac_list:
  if i < 0:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 11800
#include<stdio.h>
int main()
{
    int N,i,j,b = 0,c = 0;
    int a[10000];

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

    for(j = 0;j < N;j++){
    	while(a[j] % 2 != 1){
    		a[j] = a[j]/2;
    		b++;
    	
    	}
    	c = c + b;
    	b = 0;
    }

    printf("%d",c);

    return 0;
}

Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));
$lArray = array_map("intval", explode(" ", trim(fgets(STDIN))));
sort($lArray);
$map = [];
for($i = 1; $i <= 2000; $i++){
  $map[$i] = 0;
}
foreach($lArray as $l){
  $map[$l]++;
}
$sum = 0;
for($i = 1; $i <= 2000; $i++){
  $sum+=$map[$i];
  $accum[$i] = $sum;
}

$c = 0;
for($i = 0; $i < $n - 1; $i++){
  for($j = 0; $j < $i; $j++){
    $add = $accum[$lArray[$i] + $lArray[$j] - 1] - ($i + 1);
    $c+=max(0,$add);
  }
}
echo $c;


Measured memory_bytes: 4604
N,M =map(int,input().split())
p = list(map(lambda x:int(x)-1,input().split()))
xy = [list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
group = [i for i in range(N)]
glist = [[i] for i in range(N)]
def merge(x,y):
    gx = group[x]
    gy = group[y]
    if gx == gy:
        return
    if len(glist[gx])<len(glist[gy]):
        gx,gy = gy,gx
    for y in glist[gy]:
        group[y] = gx
    glist[gx] += glist[gy]
    glist[gy] = []
    return
for x,y in xy:
    merge(x,y)
out = sum([len(set(row) & set(p[g] for g in row)) for row in glist])
print(out)

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


int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;
	int W;
	cin >> W;

	vector<int> w(n), v(n);

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

	vector<vector<ll>> dp(n, vector<ll>(W + 1));
	
	dp[0][w[0]] = v[0];

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

	ll ans = 0;
	
	for (int i = 0; i < n; ++i) for (int j = 0; j <= W; ++j) ans = max(ans, dp[i][j]);

	cout << ans << endl;

}



Measured memory_bytes: 79488
import math
def main():
    n, h = list(map(int, input().split()))
    A, B = [], []
    for _ in range(n):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)
    a_max = max(A)
    B = list(filter(lambda x: x > a_max, B))
    B.sort(reverse = True)
    ans = 0
    for b in B:
        h -= b
        ans += 1
        if h <= 0:
            break
    else:
        ans += math.ceil(h / a_max)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++)
        {
            h[i] = sc.NextInt();
        }

        h = h.OrderBy(i => i).ToArray();

        int answer = int.MaxValue;

        for (int i = 0; i < n - k + 1; i++)
        {
            answer = Math.Min(answer, h[i + k - 1] - h[i]);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
//const int INF = INT_MAX  ;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

//< ave , a(time), b(manzoku) >
typedef tuple<double, int, int> A;

int gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

int main() {
    ll n;
    cin >> n;

    vector<ll> as(n);
    rep(i, n) {
        cin >> as[i];
    }

    ll mc = 0;
    for (ll a : as) {
        if (a < 0) {
            mc++;
        }
    }

    ll acm = 0;
    ll absMin = INF;
    for (ll a : as) {
        acm += abs(a);
        absMin = min(absMin, abs(a));
    }

    if (mc % 2 == 0) {
        cout << acm << endl;
        return 0;
    } else {
        cout << acm - 2 * absMin << endl;
    }


}



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

# define FOR(i,a,b) for (int i=(a);i<(b);i++)
# define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
# define REP(i, n) for (int i = 0; i < (int)(n); i++)
# define RREP(i,n) for (int i=(n)-1;i>=0;i--)

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}
#define MOD 1000000007
long long fact(long long k){
  long long sum = 1;
  for (long long i = 1; i <=k;i++){
    sum = (sum * i) % MOD;
  }
  return (sum);
}

int main() {
  vint(A,2);

  if(abs(A[0]-A[1])<=1){
    long long ans = 1;
    ans = (fact(A[0]) * fact(A[1])) % MOD;
    if(A[0] == A[1])
      ans = (ans*2)%MOD;
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }

}


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

int main(){
    int n;
    cin >> n;
    int num = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        num += b - a + 1;
    }

    cout << num << endl;
}

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

typedef unsigned long ul;
typedef long long int ll;
typedef pair<ll, ll> P;
#define pb push_back
#define mp make_pair
#define REP(i,n) REPN(i,0,n)
#define REPN(i,m,n) for(int i=m; i<(n); i++)
#define ALL(a) (a).begin(),(a).end()
#define dump(x) cout << #x << " = " << (x) << endl

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

    ll k, a, b;
    cin >> k >> a >> b;
    ll ans = 1 + k;
    ll diff = b - a;

    if (diff <= 0) {
        cout << ans << '\n';
        return 0;
    }

    ll pair = (k - a + 1) / 2;
    ll amari = k - pair*2;

    ll newans = 1 + ((b - a) * pair) + amari;

    if (ans < newans) {
        cout << newans << '\n';
    } else {
        cout << ans << '\n';
    }
}


Measured memory_bytes: 256
use proconio::input;
 
fn main() {
  input! {
    n: usize,
    vals: [(usize, usize, usize);n]
  }
  
  let mut dp: Vec<(usize, usize, usize)> = vec![(0,0,0);n];
  dp[0].0 = vals[0].0;
  dp[0].1 = vals[0].1;
  dp[0].2 = vals[0].2;
  
  for i in 1..n {
    dp[i].0 = vals[i].0 + std::cmp::max(dp[i-1].1, dp[i-1].2);
    dp[i].1 = vals[i].1 + std::cmp::max(dp[i-1].0, dp[i-1].2);
    dp[i].2 = vals[i].2 + std::cmp::max(dp[i-1].1, dp[i-1].0);
  }
  
  let mut result = std::cmp::max(dp[n-1].0, dp[n-1].1);
  result = std::cmp::max(result , dp[n-1].2);
  
  println!("{}", result);
}

Measured memory_bytes: 8396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int n;

    cin >> n;
    n++;

    int t[n], x[n], y[n];

    t[0] = x[0] = y[0] = 0;

    for (int i = 1; i < n; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }

    int dt, dxdy;
    for (int i = 1; i < n; i++) {
        dt = t[i] - t[i - 1];
        dxdy = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);

        if (dt < dxdy) {
            cout << "No" << endl;
            return 0;
        }

        if ((dt + dxdy) % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

int main() {
  int a,b,c,d,ans;
  cin>>a>>b>>c>>d;
  if(a<b){
    ans=a;
  }else{ans=b;}
  if(c<d){
    ans+=c;
  }else{ans+=d;}
  cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;
typedef pair <int, int> pp;
#define MAXN 300005
#define MAXM 1005
#define MAXP 25
#define INF 2000000000
#define A first
#define B second
#define MP make_pair
#define PB push_back

const ll MOD = 1e9+7;
string s;
int N;
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> s; N = s.length();
	set <char> t;
	for(int i=0; i<26; i++) t.insert((char)(i+'a'));
	for(int i=0; i<N; i++) t.erase(s[i]);
	
	if(N < 26) {
		cout << s + *t.begin() << endl;
		return 0;
	}
	for(int i=25; i>=0; i--) {
		if(t.empty()) {
			t.insert(s[i]); continue;
		}
		auto it = t.upper_bound(s[i]);
		if(it != t.end()) {
			for(int j=0; j<i; j++) cout << s[j];
			cout << *it << endl;
			return 0;
		}
		t.insert(s[i]);
	}
	cout << -1 << endl; 
	
	
}

Measured memory_bytes: 256
from sys import stdin
def S(): return stdin.readline().rstrip()
def LI(): return list(map(int,stdin.readline().rstrip().split()))

tmp = LI()
h,w = [tmp.pop(0) for i in range(2)]

c = []

for i in range(h):
    tmp = S()
    c.append(tmp)

for i in range(h):
    for k in range(2):
        print(c[i],end='')
        print()


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 N, M;
  map<string, vector<int64>> mp;
  cin >> N;
  REP(i, N) {
    string s; int64 x;
    cin >> s >> x;
    mp[s].push_back(x);
  }
  for (auto& x : mp) {
    x.sc.push_back(INF_LL);
    sort(all(x.sc));
  }
  int64 now = -1;
  cin >> M;
  REP(i, M) {
    string s;
    cin >> s;
    if (mp[s].size() == 0) {
      cout << "No" << endl;
      return 0;
    }
    int64 ret = *upper_bound(all(mp[s]), now);
    if (ret == INF_LL) {
      cout << "No" << endl;
      return 0;
    } else {
      now = ret;
    }
  }
  cout << "Yes" << endl;
}


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

int main ()
{
	string a,b;
	
	cin>>a>>b;
	
	if(a=="1" && b=="2"){
		 cout<<"3"<<endl;
	 }
else if(a=="2" && b=="1"){
		 cout<<"3"<<endl;
	 }
	  else if(a=="1" && b=="3"){
		 cout<<"2"<<endl;
	 }
	  else if(a=="3" && b=="1"){
		 cout<<"2"<<endl;
	 }
	  else if(a=="3" && b=="2"){
		 cout<<"1"<<endl;
	 }
	   else if(a=="2" && b=="3"){
		 cout<<"1"<<endl;
	 }
	


}



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

int main(){
    int k, s;
    cin >> k >> s;

    int count = 0;
    for (auto x = 0; x <= k; x++) {
        for (auto y = 0; y <= k; y++) {
            int z = s - x - y;
            if(z >= 0 && z <= k) count++;
        }
    }

    cout << count << endl;
    return 0;
}

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

using namespace std;

int n, m, row[105], col[105], del_row[105], del_col[105];
char a[105][105];

int main() {
	cin >> n >> m;
	char c;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) {
			cin >> c;
			int d = c == '#' ? 1 : 0;
			a[i][j] = c;
			if(!d) row[i]++, col[j]++;
		}
	for(int i = 1; i <= n; i++)
		if(row[i] == m) del_row[i] = 1;
	for(int j = 1; j <= m; j++)
		if(col[j] == n) del_col[j] = 1;
	for(int i = 1; i <= n; i++) {
		if(del_row[i]) continue;
		for(int j = 1; j <= m; j++)
			if(!del_col[j]) cout << a[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256