akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
typedef long long ll;
ll h, w, a[30], b[3];
string str[110];
int main(void){
    // Your code here!
    cin >> h >> w;
    for (ll i = 0; i < h; i++) cin >> str[i];
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w; j++) {
            a[str[i][j] - 'a']++;
        }
    }
    for (ll i = 0; i < 26; i++) {
        if (a[i] % 4 == 0) b[0]++;
        else if (a[i] % 4 == 2) b[1]++;
        else b[2]++;
    }
    if (h % 2 && w % 2) {
        if (b[2] == 1 && h / 2 + w / 2 >= b[1]) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else if (h % 2 == 0 && w % 2 == 0) {
        if (b[2] == 0 && b[1] == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else if (h % 2 == 0 && w % 2) {
        if (b[2] == 0 && h / 2 >= b[1]) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        if (b[2] == 0 && w / 2 >= b[1]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main(){
    int X;
    cin >> X;
    int N = X / 100 , T = X % 100;
    cout << (N * 5 >= T) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, n; cin >> x >> n;
    vll p(201, 0);
    for (ll i = 0; i < n; i++) {
        ll tmpp; cin >> tmpp;
        p[tmpp] = 1;
    }

    for (ll i = 0; i <= 100; i++) {
        if (p[x - i] == 0) {
            cout << x - i << '\n';
            return 0;
        }
        if (p[x + i] == 0) {
            cout << x + i << '\n';
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3652
def gcd(a,b):
  if b == 0: return a
  return gcd(b,a%b)
def lcm(c,d):
   return c*d/gcd(a,b)
while True:
 try:
  a,b = map(int,raw_input().split())
  c,d = a,b
  print gcd(a,b),lcm(c,d)
 except EOFError: break

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
int main(){
  int N;cin>>N;
  vector<LL>A(N),B(N);
  for(LL &a:A)cin>>a;
  for(LL &b:B)cin>>b;
  vector<LL>t;
  LL u=0,c=0;
  for(int i=0;i<N;i++){
    if(A[i]>=B[i])
      t.push_back(A[i]-B[i]);
    else{
      u+=B[i]-A[i];
      c++;
    }
  }
  sort(t.begin(),t.end(),greater<LL>());
  LL sum=0;
  for(int i=0;i<=t.size();sum+=t[i],i++){
    if(sum>=u){
      cout<<c+i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 2936
while True:
  try:
    l = input().rstrip()
    [a,b] = l.split("+")
    [c,d] = b.split("=")
    for i in range(10):
      if i == 0:
        if (a[0] == "X" != a) or (c[0] == "X" != c) or (d[0] == "X" != d):
          pass
        else:
          A = int(a.replace("X",str(i)))
          C = int(c.replace("X",str(i)))
          D = int(d.replace("X",str(i)))
          if A+C == D:
            print(i)
            break
      else:
        A = int(a.replace("X",str(i)))
        C = int(c.replace("X",str(i)))
        D = int(d.replace("X",str(i)))
        if A+C == D:
          print(i)
          break
    else:
      print('NA')
  except:
    break

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

using namespace std;

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

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

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



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, con = 0;
	vector<int> A, B;
	
	cin>>N;
	
	A.resize(N+2);
	B.resize(N+1);
	
	for(int i = 0; i <= N; i++){
		cin>>A[i];
	}
	
	for(int i = 0; i < N; i++){
		cin>>B[i];
	}
	
	for(int i = N-1; i >= 0; i--){
		int a, b;
		con += min(A[i+1],B[i]);
		B[i] -= min(A[i+1],B[i]);
		con += min(A[i],B[i]);
		a = min(A[i],B[i]);
		B[i] -= a;
		A[i] -= a;
	}
	
	cout<<con<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
monster = list(map(int, input().split()))
defeatable = list(map(int, input().split()))
start = sum(monster)
for idx in range(n) :
    if defeatable[idx] <= monster[idx] :
        monster[idx] -= defeatable[idx]
        defeatable[idx] = 0
    else :
        defeatable[idx] -= monster[idx]
        monster[idx] = 0
        if defeatable[idx] <= monster[idx+1] :
            monster[idx+1] -= defeatable[idx]
            defeatable[idx] = 0
        else :
            defeatable[idx] -= monster[idx+1]
            monster[idx+1] = 0
print(start-sum(monster))


Measured memory_bytes: 23920
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i = x;i<n;i++)
#define S(v) sort(v.begin(), v.end());
#define ff first
#define ss second


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	// freopen("in.txt","r", stdin);
	ll n;
	cin>>n;
	vector<ll> v(n);
	loop(i,0,n)cin>>v[i];
	ll ans = 0;
	loop(i, 1, n-1){
		if(v[i] > v[i+1] && v[i] < v[i-1])ans++;
		else if(v[i] < v[i+1] && v[i] > v[i-1])ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3656
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
		}
		Arrays.sort(a);
		int ans = 200*200*100;
		for(int i = a[0];i <= a[n-1];i++){
			ans = Math.min(ans, solve(i, a));
		}
		System.out.println(ans);
	}
	
	public static int solve(int mid,int[] a){
		int ans = 0;
		int num = 0;
		for(int i = 0;i < a.length;i++){
			num = a[i] - mid;
			ans = ans + num*num;
		}
		return ans;
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

vector<int> get_primes(int n) {
  vector<int> primes;
  primes.push_back(2);
  for (int i=3; i<=n; i+=2) {
    bool ok = true;
    for (int j=3; j<i; j+=2) {
      if (i % j == 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      primes.push_back(i);
    }
  }
  return primes;
}
int main() {
  int n;
  cin>>n;
  map<int, int> m;
  vector<int> primes = get_primes(n);
  for (int i=2; i<=n; i++) {
    int k = i;
    for (int p: primes) {
      while (k % p == 0) {
        ++m[p];
        k /= p;
      }
    }
  }
  int cnt2 = 0, cnt4 = 0, cnt14 = 0, cnt24 = 0, cnt74 = 0;
  for (auto e: m) {
    int v = e.second;
    if (v >= 2) {
      ++cnt2;
    }
    if (v >= 4) {
      ++cnt4;
    }
    if (v >= 14) {
      ++cnt14;
    }
    if (v >= 24) {
      ++cnt24;
    }
    if (v >= 74) {
      ++cnt74;
    }
  }
  int ans = max(cnt4 * (cnt4 - 1) / 2 * (cnt2 - 2), 0)
            + cnt24 * (cnt2 - 1)
            + cnt14 * (cnt4 - 1)
            + cnt74;
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int MIN(int a,int b){return a<b?a:b;}
int n,m,i,j,d[210][10100],a,b,c,max=0;
int main(){
  scanf("%d %d",&n,&m);
  for(i=0;i<210;i++){
    for(j=0;j<10010;j++)d[i][j]=-1;
  }
  d[0][0]=0;
  while(n--){
    scanf("%d %d %d",&a,&b,&c);
    for(i=m;i>-1;i--){
      for(j=10000;j>-1;j--){
	if(d[i][j]==-1)continue;
	d[i+c][j+a]=MAX(d[i+c][j+a],d[i][j]+b);
	d[i+c][j+b]=MAX(d[i+c][j+b],d[i][j]+a);
      }
    }
  }
  for(i=0;i<=m;i++){
    for(j=0;j<10000;j++){//printf("%2d ",d[i][j]);
      if(d[i][j]==-1)continue;//printf("%d %d\n",j,d[i][j]);
      max=MAX(max,MIN(j,d[i][j]));
    }//printf("\n");
  }
  printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 10112
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        if(n>=30)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 35608
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    int alphabeticalCounter[26];
    for (int i = 0; i < 26; i++)
            alphabeticalCounter[i] = 0;
    while (getline(cin, s)) {
        
        
    
        for (int i = 0; i < s.size(); i++) {
            char c = s[i];
            if (c >= 'a' && c <= 'z')
                alphabeticalCounter[c - 'a']++;
            else if (c >= 'A' && c <= 'Z')
                alphabeticalCounter[c - 'A']++;
        }
    }
    
    for (int i = 0; i < 26; i++) {
            cout << static_cast<char>('a' + i) << " : ";
            cout << alphabeticalCounter[i] << endl;
        }
    return 0;
}



Measured memory_bytes: 3160
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/


void solve() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	unordered_map<int, int> m; int ans = 0;
	for (int i = 0; i < n; i++) {
		if (m.count(i - a[i])) ans += m[i - a[i]];
		m[i + a[i]]++;
	}
	cout << ans << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 12916
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String alp = "abcdefghijklmnopqrstuvwxyz";
		int[] a = new int[alp.length()];
		for(int i=0; i<s.length(); i++){
			for(int j=0; j<alp.length(); j++){
				if(s.charAt(i) == alp.charAt(j)){
					a[j]++;
				}
			}
		}
		String result = "Yes";
		for(int i : a){
			if(i % 2 != 0){
				result = "No";
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 35452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF=1LL<<60;
int main(){
    int a,b;cin >> a >> b;
    for(int i=1;i<=1100;i++){
        if(i*108/100-i==a&&i*110/100-i==b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
const ll MOD=1e9+7;

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

	int N;
	cin >> N;
	vector<vector<int>> x(N);
	FOR(i,0,N-1){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		x[a].push_back(b);
		x[b].push_back(a);
	}

	vector<bool> did(N,false);
	vector<int> p(N,0),cnum(N,0);

	did[0] = true;
	queue<int> q;
	q.push(0);
	while(!q.empty()){
		for(auto c:x[q.front()]){
			if(!did[c]){
				did[c] = true;
				q.push(c);
				p[c] = q.front();
				cnum[q.front()]++;
			}
		}
		q.pop();
	}


	auto dp = vector<vector<ll>>(N,vector<ll>(2,1));

	FOR(i,0,N){
		if(cnum[i]==0){
			q.push(i);
		}
	}
	while(!q.empty()){
		if(p[q.front()]==q.front()){
			q.pop();
			continue;
		}
		cnum[p[q.front()]]--;
		if((cnum[p[q.front()]]==0)&&(p[q.front()]!=0))q.push(p[q.front()]);
		( dp[p[q.front()]][1] *= (dp[q.front()][0]+dp[q.front()][1])%MOD ) %= MOD;
		( dp[p[q.front()]][0] *= dp[q.front()][1] ) %= MOD;
		q.pop();
	}

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

}

Measured memory_bytes: 13004
#include<iostream>
#include<string>
#include<map>

int main() {
	std::map<std::string, int> words;
	int maxlen = 0, maxfreq = 0;
	std::string word, letword, freqword;
	while (std::cin >> word) {
		if (maxlen < word.length()) {
			maxlen = word.length();
			letword = word;
		}
		if (words.find(word) == words.end()) {
			words[word] = 1;
		}
		else {
			words[word] += 1;
		}
		if (maxfreq < words[word]) {
			maxfreq = words[word];
			freqword = word;
		}
	}
	std::cout << freqword << " " << letword << std::endl;

	return 0;
}


Measured memory_bytes: 3012
#include <iostream>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <functional>
#include <climits>
#include <string>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int a[503][503];//i駅から始まり、j駅で終わる電車の数
	int ruiseki[503][503];
	int ruiseki2[503][503];
	int n, m, q;
	cin >> n >> m >> q;
	int l, r;
	for (int i = 0; i < 503; i++) {
		for (int j = 0; j < 503; j++) {
			a[i][j] = 0;
			ruiseki[i][j] = 0;
			ruiseki2[i][j] = 0;
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> l >> r;
		a[l][r] += 1;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			ruiseki[i][j] = ruiseki[i][j - 1] + a[i][j];
		}
	}
	for (int j = 1; j <= n; j++) {
		for (int i = j; i >=1; i--) {
			if (i == j)ruiseki2[i][j] = ruiseki[i][j];
			else ruiseki2[i][j] = ruiseki2[i + 1][j] + ruiseki[i][j];
		}
	}
	int pp, qq;
	for (int z = 0; z < q; z++) {
		cin >> pp >> qq;
		cout << ruiseki2[pp][qq]<<"\n";
	}
	return 0;
}



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

int main(void) {

  int n, T;
  cin >> n >> T;

  vector<int> cs;
  cs.resize(n);

  int m = 10000;

  for(int i = 0; i < n; i++)
  {
    int c, t;
    cin >> c >> t;
    if (t <= T)
      m = min(c, m);
  }

  if (m == 10000)
    cout << "TLE" << endl;
  else
    cout << m << endl;
  return 0;
}

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

int main() {
  string s[15]={"Rock","Fire","Scissors","Snake","Human","Tree","Wolf","Sponge","Paper","Air","Water","Dragon","Devil","Lightning","Gun"};
  map<string,int> r;
  for(int i=0; i<15; i++) r[s[i]]=i;
  int n;
  while(cin >> n && n) {
    map<string,int> m;
    string t[n];
    for(int i=0; i<n; i++) {
      cin >> t[i];
      m[t[i]]++;
    }
    set<string> ans;
    for(int i=0; i<n; i++) {
      int k=r[t[i]];
      int c=0,c2=0;
      for(int j=0; j<7; j++) c+=m[s[(k+j+1)%15]];
      for(int j=0; j<7; j++) c2+=m[s[(k+j+8)%15]];
      if(c&&!c2) ans.insert(t[i]);
    }
    if(ans.size()==1) cout << *ans.begin() << endl;
    else cout << "Draw" << endl;
  }
  return 0;
}

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

typedef struct Pr {
	string name;
	double eff;
	bool eq(const Pr &r) {
		return fabs(eff - r.eff) < 0.0000001;
	}
	bool operator<(const Pr &r) {
		return (eq(r) ? (name < r.name) : (eff > r.eff));
	}
} Pr;

int N, P, A, B, C, D, E , F, S, M;
string L;
Pr p[50];

int main(){
	while (cin >> N && N != 0) {
		for (int i = 0; i < N; i++) {
			cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
			p[i].name = L;
			p[i].eff = 1.0*(F*S*M - P) / (A + B + C + (D + E)*M);
		}
		sort(p, p + N);
		for (int i = 0; i < N; i++) {
			cout << p[i].name << endl;
		}
		cout << "#" << endl;
	}

	return 0;
}

Measured memory_bytes: 3056
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0277();
	}
	
	class AOJ0277{
		public AOJ0277() {
			int[] tickets = new int[4];
			int[] kane = {6000,4000,3000,2000};
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i=0;i<4;i++){
				list.add(in.nextInt()-1);
				tickets[list.get(list.size()-1)] = in.nextInt();
			}
			for(int i=0;i<list.size();i++)System.out.println(kane[list.get(i)]*tickets[list.get(i)]);
		}
	}
}

Measured memory_bytes: 17372
open Batteries

let main () =
  let n, s = Scanf.scanf "%d\n%s" (fun x y -> x, y) in
  let now = ref @@ String.fold_left (fun acc x -> if Char.equal x 'E' then acc + 1 else acc) 0 s - if Char.equal 'E' s.[0] then 1 else 0 in
  let ans = ref !now in
  for i = 1 to n - 1 do
    if Char.equal s.[i-1] 'W' then now := !now + 1;
    if Char.equal s.[i] 'E' then now := !now - 1;
    ans := min !now !ans;
  done;
  Printf.printf "%d\n" !ans

let _ = main ()


Measured memory_bytes: 4096
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int>P;
typedef pair<long long,P>P1;
#define pb push_back
#define mp make_pair
P pa1[100005],pa2[100005];
int h,w,n;
bool comp(P a,P b){
	return a.second<b.second;
}
bool decide(P1 a,P1 b){
	if(a.first<b.first){
		return true;
	}else if(a.first>b.first){
		return false;
	}else{
		if(a.second.first<b.second.first){
			return true;
		}else if(a.second.first>b.second.first){
			return false;
		}else{
			return a.second.second<b.second.second;
		}
	}
}
int main(){
	scanf("%d %d",&h,&w);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		pa2[i]=pa1[i]=mp(x,y);
	}
	sort(pa2+1,pa2+(n+1),comp);
	sort(pa1+1,pa1+(n+1));
	int ha=(n+1)/2;
	int ax=pa1[ha].first;
	int ay=pa2[ha].second;
	vector<P1>vec;
	vector<int>dx,dy;
	dx.pb(ax);
	dy.pb(ay);
	if(pa1[ha+1].first!=ax){
		dx.pb(pa1[ha+1].first);
	}
	if(pa2[ha+1].second!=ay){
		dy.pb(pa2[ha+1].second);
	}
	for(int i=0;i<dx.size();i++){
		for(int j=0;j<dy.size();j++){
			long long sd=0;
			int maxi=0;
			for(int g=1;g<=n;g++){
				sd+=(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j]));
				maxi=max(maxi,(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j])));
			}
			vec.pb(mp(sd*2-maxi,mp(dx[i],dy[j])));
		}
	}
	sort(vec.begin(),vec.end(),decide);
	printf("%lld\n%d %d\n",vec[0].first,vec[0].second.first,vec[0].second.second);
	return 0;
}

Measured memory_bytes: 2620
//use proconio::input;
use std::cmp::min;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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() {
    input! {
        n: usize,
        h: [i32; n],
    }
    let mut dp = vec![0; n];
    let m = 2;
    dp[1] = (h[1] - h[0]).abs();
    for i in m..n {
        let mut dpi = dp[i - 1] + (h[i] - h[i - 1]).abs();
        for j in 1..(m + 1) {
            dpi = min(dpi, dp[i - j] + (h[i] - h[i - j]).abs());
        }
        dp[i] = dpi;
    }

    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n,i,j,k,t,temp,tc;
    map<LL,LL> grid;
    LL sum=0;
    LL q;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>j;
        grid[j]++;
        sum+=j;
    }

    cin>>q;
    while(q--)
    {
        cin>>j>>k;
        LL y=grid[j];
        sum+=(k-j)*y;
        grid[j]-=y;
        grid[k]+=y;
        cout<<sum<<endl;
    }

    return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

ll mod = 1e9 + 7;

ll fact(ll x) {
	ll res = 1;
	rep(i, x)res = res * (ll(i) + 1LL) % mod;
	return res;
}

int main() {
	ll a,b;
	cin >> a >> b;
	if (abs(a - b) > 1) { cout << 0 << endl; return 0; }
	ll ans = fact(a) * fact(b) % mod;
	if (a == b)ans = 2LL * ans % mod;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	ll a[100000];
	ll goukei = 0;
	rep(i, N) {
		cin >> a[i];
		goukei ^= a[i];
	}

	int M = 60;
	int r = 0;
	for (int i = M - 1; i >= 0; i--) {
		if (!(goukei >> i & 1)) {
			for (int j = r; j < N; j++) {
				if (a[j] >> i & 1) {
					swap(a[r], a[j]);
					for (int k = max(j, r + 1); k < N; k++) {
						if (a[k] >> i & 1) {
							a[k] ^= a[r];
						}
					}
					if (!(a[0] >> i & 1)) {
						a[0] ^= a[r];
					}
					r++;
					break;
				}
			}
		}
	}

	co(a[0] + (a[0] ^ goukei));

	Would you please return 0;
}

Measured memory_bytes: 1024
# 解説見た
n,k = map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(k)]
dp = [0]*(n+1)
sdp = [0]*(n+1)
dp[1],sdp[1] = 1,1
mod = 998244353

for i in range(1,n+1):
    for l,r in lr:
        if i-l<0:
            continue
        else:
            dp[i] += sdp[i-l] - sdp[max(0,i-r-1)]
    sdp[i] = sdp[i-1] + dp[i]
    dp[i] %= mod
    sdp[i] %= mod
    
print(dp[-1])

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N=S.size(), min=INF;
  REP(i,N-2) {
    int X=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
    if(abs(X-753)<=min) min=abs(X-753);
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M, P[101010], X[101010], Y[101010];

int uf[101010];
int root(int p)
{
	return uf[p] < 0 ? p : (uf[p] = root(uf[p]));
}
void join(int p, int q)
{
	p = root(p);
	q = root(q);
	if (p == q) return;
	uf[p] += uf[q];
	uf[q] = p;
}

vector<int> grp[101010];

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) {
		scanf("%d", P + i);
		--P[i];
	}
	for (int i = 0; i < M; ++i) {
		scanf("%d%d", X + i, Y + i);
		--X[i]; --Y[i];
	}
	for (int i = 0; i < N; ++i) uf[i] = -1;
	for (int i = 0; i < M; ++i) join(X[i], Y[i]);

	for (int i = 0; i < N; ++i) {
		grp[root(i)].push_back(i);
	}

	int ret = 0;
	for (int i = 0; i < N; ++i) if (grp[i].size() > 0) {
		set<int> val;
		for (int j : grp[i]) val.insert(P[j]);

		for (int j : grp[i]) ret += val.count(j);
	}

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

	return 0;
}


Measured memory_bytes: 9208
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;


int main(){
	int W,N,count = 1,max_v,max_w;

	int** dp = new int*[1001];
	for(int i=0; i < 1001; i++){
		dp[i] = new int[1001];
	}

	while(true){
		scanf("%d",&W);
		if(W == 0)break;

		for(int i = 0; i < 1001; i++){
			for(int k=0; k < 1001; k++)dp[i][k] = 0;
		}

		max_v = max_w = -1;

		scanf("%d",&N);

		int v[N],w[N];

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

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

		for(int i = W; i >=0; i--){
			if(dp[0][i] >= max_v){
				max_v = dp[0][i];
				max_w = i;
			}
		}

		printf("Case %d:\n%d\n%d\n",count,max_v,max_w);
		count++;
	}


	return 0;
}

Measured memory_bytes: 6564
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)


func main()  {
	sc.Scan()
	in := sc.Text()
	val, _ := strconv.Atoi(in)

	if val % 111 == 0 {
		fmt.Println(val)
	} else {
		fmt.Println((val/111) * 111 + 111)
	}
}


Measured memory_bytes: 640
N,A,B = map(int,input().split())

def sumofDigits(num):
    sumDigits = 0
    for j in range(len(num)):
        sumDigits += int(num[j])
    return sumDigits

total_sumDigits = 0

for i in range(1,N+1):
    if A <= sumofDigits(str(i)) <= B:
        total_sumDigits += i

print(total_sumDigits)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll const mod=1e9+7;
double const pi=acos(-1);
ll s[100500];
int flag;	
ll x;
int main()
{
	
	for(ll i=0;i<=1000;i++)
	{
		ll sum1=1;
		for(int j=0;j<5;j++)
		{
			sum1*=i;
		}
		s[i]=sum1;
		//cout<<sum1<<endl;
	}
	cin>>x;
	for(int i=0;i<=1000;i++)
	{
		for(int j=0;j<=1000;j++)
		{
			if(s[i]-s[j]==x)
			{
				cout<<i<<" "<<j<<endl;
				flag=1;
				break;
			}else if(s[i]+s[j]==x)
			{
				cout<<i<<" "<<-j<<endl;
				flag=1;
				break;
			}
			
		}
		if(flag)
		{
			break;
		}
	}
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

ll w[105],v[105];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n,W;
  cin>>n>>W;
  forn(i,0,n) cin>>w[i]>>v[i];
  vector <ll> dp(1e5+1,1e18),new_dp(1e5+1,0);
  dp[0]=0;
  for(ll i=0;i<n;i++){
    for(ll value=1;value<=1e5;value++){
      ll a=1e18,b=1e18;
      if(value-v[i]>=0)
        a=dp[value-v[i]]+w[i];
      if(value>=0)
        b=dp[value];
      new_dp[value]=min(a,b);
    }
    dp=new_dp;
    /*cout<<i<<" : ";
    for(auto it:dp)
      cout<<it<<" ";
    cout<<endl;*/
  }
  ll ans=0;
  for(ll value=1e5;value>=0;value--){
    if(dp[value]<=W)
      {
        ans=value;
        break;
      }
  }
  cout<<ans<<endl;
  return 0;
}


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

namespace dwacon5th_prelims_b
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long[] sum = new long[x[0] + 1];
			for (int i = 0; i < x[0]; i++)
			{
				sum[i + 1] = sum[i] + a[i];
			}
			List<long> list = new List<long>();
			for (int i = 0; i <= x[0]; i++)
			{
				for (int j = i + 1; j <= x[0]; j++)
				{
					long now = sum[j] - sum[i];
					list.Add(now);
				}
			}
			long ret = 0;
			for (int i = 40; i >= 0; i--)
			{
				List<long> ok = new List<long>();
				foreach (var item in list)
				{
					if ((item & 1L << i) > 0) ok.Add(item);
				}
				if (ok.Count >= x[1])
				{
					ret += 1L << i; list = ok;
				}
			}
			Console.WriteLine(ret);
		}
	}
}

Measured memory_bytes: 27488
import numpy as np

def main():
    N = int(input())

    i = 1
    ans = 0
    while N >= 10**i:
        if i % 2 == 1:
            ans += 9 * 10**(i-1)
        i += 1

    if i % 2 == 1:
        ans += N - 10**(i-1)+ 1

    print(ans)





if __name__ == "__main__": 
    main()

Measured memory_bytes: 21640
#include<cstdio>

typedef long long int lli;

#define MOD 1000000007ULL

lli x[500][500];
lli a[500];
lli b[500];

inline lli powm(lli a, lli b) {
    lli res = 1;
    while(b) {
        if(b & 1)
            res *= a, res %= MOD;
        a *= a, a %= MOD;
        b /= 2;
    }
    return res;
}

lli dp[500][500]; // i番目までの子供にj個配ったとき

int main(void) {
    int n,c;
    scanf("%d%d",&n,&c);
    for(int i=0; i<n; i++)
        scanf("%lld",&a[i]);
    for(int i=0; i<n; i++)
        scanf("%lld",&b[i]);

    for(int i=0; i<n; i++)
        for(int j=0; j<=c; j++)
            for(lli k=a[i]; k<=b[i]; k++)
                x[i][j] += powm(k, j), x[i][j] %= MOD;

    dp[0][0] = 1;
    //for(int i=0; i<500; i++)
        //dp[0][i] = 1;

    for(int i=0; i<n; i++)
        for(int j=0; j<=c; j++)
            for(int k=0; k<=j; k++)
                dp[i+1][j] += dp[i][k] * x[i][j-k], dp[i+1][j] %= MOD;

    for(int i=0; i<=n; i++)
        for(int j=0; j<=c; j++)
            0;//printf("%d %d  %d\n", i, j, dp[i][j]);


    printf("%lld\n", dp[n][c]);

    return 0;
}


Measured memory_bytes: 3328
#include <cstdio>

int s[10001] = {0};
int n,q;

int top(int x){
	if(s[x] == x){
		return x;
	}
	return top(s[x]);
}
int len(int x,int l=0){
	if(s[x] == x){
		return l;
	}
	return len(s[x],l+1);
}

int uni(int x,int y){
	int lx = len(x);
	int ly = len(y);
	int tx = top(x);
	int ty = top(y);
	if(lx < ly){
		s[ty] = tx;
	}
	else{
		s[tx] = ty;
	}
	return 0;
}

bool same(int x,int y){
	return top(x) == top(y);
}

int main(){
	scanf("%d%d",&n,&q);
	for(int i = 1; i < n; i++){
		s[i] = i;
	}
	int com,x,y;
	for(int I = 0; I < q; I++){
		scanf("%d%d%d",&com,&x,&y);
		if(com == 0){
			uni(x,y);
		}
		else{
			printf("%d\n",same(x,y) ? 1 : 0);
		}
	}
	return 0;
}



Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

void solve(){
    ll n, x, y; cin >> n >> x >> y;
    x --; y --;
    vector<vector<ll>> E(n);
    rep(_, n - 1){
        ll u, v; cin >> u >> v;
        u --; v --;
        E[u].push_back(v);
        E[v].push_back(u);
    }

    // x rooted depth
    vector<ll> xdepth(n, -1);
    xdepth[x] = 0;
    vector<ll> stack{x};
    while(!stack.empty()){
        ll v = stack.back(); stack.pop_back();
        for(auto& nv : E[v]){
            if(xdepth[nv] != -1){
                continue;
            }
            xdepth[nv] = xdepth[v] + 1;
            stack.push_back(nv);
        }
    }

    // y rooted depth
    vector<ll> ydepth(n, -1);
    ydepth[y] = 0;
    stack.clear();
    stack.push_back(y);
    while(!stack.empty()){
        ll v = stack.back(); stack.pop_back();
        for(auto& nv : E[v]){
            if(ydepth[nv] != -1){
                continue;
            }
            ydepth[nv] = ydepth[v] + 1;
            stack.push_back(nv);
        }
    }

    ll res = 0;
    rep(v, n){
        if(xdepth[v] < ydepth[v]){
            chmax(res, ydepth[v] - 1);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 7936
# ~10m AC
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b = LI()

min_s = a * (n - 1) + b
max_s = a + (n - 1) * b
ans = max_s - min_s + 1
if ans < 0:
    ans = 0
print(ans)


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

int main(void){
	int A,B,T;

	cin>>A>>B>>T;
	cout<<B*(T/A)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int N,i,j,*A,v;
  
  scanf("%d",&N);
  A=malloc(N*sizeof(int*));
  for(i=0;i<N;i++){
  
    scanf("%d",&A[i]);
    if(i==N-1)printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  
 
  /*irekae*/
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
     
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
      
     }
     A[j+1]=v;
     for(j=0;j<N;j++){
       if(j==N-1) printf("%d\n",A[j]);
       else printf("%d ",A[j]);
      
     }
    
  }
  
 
  return 0;
}



Measured memory_bytes: 2144
#include <stdio.h>          // printf(), scanf(), fgets()
#include <stdbool.h>
#include <string.h>         // strncmp()

int
main(int argc, char **argv)
{
	int n;
	int i, j;

	scanf("%d\n", &n);
	for (j = 0; j < n; ++j)
	{
		int point = 0;
		int out = 0;
		bool runner[5];

		for (i = 1; i <= 3; ++i)
			runner[i] = false;

		while (true)
		{
			char str[9];

			if (fgets(str, sizeof(str), stdin) == NULL)
				goto l_end;

			if (strncmp(str, "OUT", 3) == 0)
			{
				out++;
				if (out >= 3)
					break;
			}

			else if (strncmp(str, "HIT", 3) == 0)
			{
				runner[4] = false;
				for (i = 3; i >= 1; --i)
				{
					if (runner[i])
					{
						runner[i + 1] = true;
						runner[i] = false;
					}
				}

				if (runner[4])
					point++;

				runner[1] = true;
			}

			else if (strncmp(str, "HOMERUN", 7) == 0)
			{
				for (i = 3; i >= 1; --i)
				{
					if (runner[i])
					{
						point++;
						runner[i] = false;
					}
				}

				point++;
			}
		}

		printf("%d\n", point);
	}

l_end:
	return 0;
}

Measured memory_bytes: 600
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e6 + 10 , P = 998244353;
int Pow(int x,int t){int r=1;for(;t;t>>=1,x=ll(x)*x%P)if(t&1)r=ll(r)*x%P;return r;}
inline void pp(int &x,int d){if((x+=d)>=P)x-=P;}
int inv[N] = {1} , fac[N] = {1} , ifac[N];
int n , m;
int comb(int a,int b){
    return ll(fac[a])*ifac[b]%P*ifac[a-b]%P;
}
int f(int n,int m,int a,int b){
    if(n>=0&&m>=0&&a>=0&&a<=n&&b>=0&&b<=m)
        return ll(comb(n+m-a-b,n-a))*comb(a+b,b)%P;
    return 0;
}

int main(){
    cin >> n >> m;
    if(n < m) swap(n , m);
    int tot = n + m + 1;
    rep(i,1,tot) fac[i]=ll(fac[i-1])*i%P;
    ifac[tot-1]=Pow(fac[tot-1],P-2);
    per(i,1,tot) ifac[i-1]=ll(ifac[i])*i%P;
    rep(i,1,tot) inv[i]=ll(fac[i-1])*ifac[i]%P;
    int ans = 0 , ver = 0 , hor = 0 , s = 0;
    int vx = 0 , vy = 0 , hx = 0 , hy = 0;
    rep(i,1,tot) {
        {
            int nx = vx + (~i & 1);
            int ny = vy + (i & 1);
            if(i == 1) nx = 1 , ny = 0 , ver = f(n-1,m,nx-1,ny);
            else if(nx == vx) pp(ver , f(n-2,m,nx-2,ny));
            else pp(ver , P-f(n-1,m-1,nx-2,ny));
            vx = nx , vy = ny;
        }
        {
            int nx = hx + (i & 1);
            int ny = hy + (~i & 1);
            if(i == 1) nx = 0 , ny = 1 , hor = f(n,m-1,nx,ny-1);
            else if(nx == hx) pp(hor , P-f(n-1,m-1,nx,ny-2));
            else pp(hor , f(n,m-2,nx,ny-2));
            hx = nx , hy = ny;
        }
        pp(s , hor);
        pp(s , ver);
        pp(ans , (ll)s*inv[i]%P);
    }
    ans = ll(ans)*Pow(comb(n+m,n),P-2)%P;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 11904
#include<stdio.h>
int main(void){
	int A,B,C,K,max;
	scanf("%d %d %d %d",&A,&B,&C,&K);
	if(K<=A){
		max=K;
	}
	if((A<K)&&(K<=A+B)){
		max=A;
	}
	if((A+B)<K){
		max=A-(K-A-B);
	}
	printf("%d\n",max);
}

Measured memory_bytes: 1708
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define setp(x) setprecision(x)
#define nep(x) next_permutation(x);
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

int main() {
    int N;
    cin >> N;
    vector<int> D(N);
    for(int i = 0; i < N; i++) cin >> D[i];
    sort(all(D));
    cout << D[N / 2] - D[N / 2 - 1] << endl;
}


Measured memory_bytes: 640
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> myds;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define F first
#define S second
#define vec(x) vector<x> 
#define pi(x,y) pair<x,y>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define all(x) x.begin(),x.end()
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repd(i,x,y,k) for(int i=x;i<y;i+=k)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define rev(x) reverse(all(x))
#define full(x,a) memset(x,a,sizeof(x))
#define lcm(x,y) ((x*y)/__gcd(x,y))
#define mod 1000000007
#define bitcount __builtin_popcountll
#define pb push_back
#define indexof order_of_key
#define valueat find_by_order

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dxx[8]={0,0,1,-1,-1,-1,1,1};
int dyy[8]={1,-1,0,0,-1,1,1,-1};

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


Measured memory_bytes: 3648
class Main
  def self.main lines
    a,b,k = lines[0].split.map(&:to_i)
    c=0    
    [a,b].min.downto(1) do |x|
      if a % x == 0 && b % x == 0 then
        c += 1
        if c == k then
          return x
        end
      end
    end
  end
end

if $0 == __FILE__
  $stdout = open('/dev/null', 'w')
  r = Main.main STDIN.readlines
  $stdout = STDOUT
  puts r
end

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int k=2;
	while (k*(k-1)<2*n)
	{
		++k;
	}
	if (k*(k-1)!=2*n)
	{
		cout<<"No\n";
		return 0;
	}
	cout<<"Yes\n"<<k<<endl;
	int s=k-1,ans[k][s],now=1;
	for (int i = 0; i < k; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			ans[i][j]=ans[j][i-1];
		}
		for (int j = i; j < s; ++j)
		{
			ans[i][j]=now;
			++now;
		}
	}
	for (int i = 0; i < k; ++i)
	{
		cout<<s;
		for (int j = 0; j < s; ++j)
		{
			cout<<" "<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
 
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;
const int MAXN = 2345;
int dis[MAXN][MAXN];
int cnt[MAXN];
 
int main() {
    int N, X, Y;
    scanf("%d %d %d", &N, &X, &Y);
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            dis[i][j] = min({j - i, abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j)});
            cnt[dis[i][j]]++;
        }
    }
    for (int i = 1; i < N; i++)
        printf("%d\n", cnt[i]);
    return 0;
}

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

int main(){
  int n,d=1,c=0;
  cin>>n;
  int b[n];
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  while(d==1){
    for(int i=0;i<n;i++){
      if(b[i]%2 == 0){
        b[i]=b[i]/2;
        c++;
      }else{
        d++;
      }
    }
  }
  cout<<c/n<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int d[]=new int[N];
		for(int i=0;i<N;i++) {
			d[i]=sc.nextInt();
		}
		Arrays.sort(d);

		System.out.println(d[N/2]-d[N/2-1]);


	}
}

Measured memory_bytes: 50344
#include <stdio.h>

int main(void)
{
   int a,b,c,s;

   scanf("%d",&s);

   if(3600 <= s){
      a = s/3600;
      b = (s-a*3600)/60;
      c = s-(a*3600+b*60);
   }else if(60 <= s && s < 3600){
      a = 0;
      b = s/60;
      c = s-b*60;
   }else if(s <60){
      a = 0;
      b = 0;
      c = s;
   }

   printf("%d:%d:%d\n",a,b,c);

   return 0;
}

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

int main()
{
        ll N, K;
        cin >> N >> K;
        vector<ll> L(N, 0);
        for (int i = 0; i < N; ++i) {
                cin >> L[i];
        }
        sort(L.begin(), L.end(), greater<ll>());
        ll ans = 0;
        for (int i = 0; i < K; ++i) {
                ans += L[i];
        }
        cout << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
        string str;
        cin >> str;
        int counter=0;
        for(int i=0 ; i<str.size() ; i++ ){
                if(str[i]=='+')
                        counter++;
                else counter--;
        }
        cout << counter << endl;
        return 0;
}

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

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

	int A[n];

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

	sort(A,A+n);

	float tot = A[0];
	for(int i=1;i<n;++i)
	{
		tot += A[i];
		tot/=2;
	}

	cout<<tot<<"\n";

	return 0;
}

Measured memory_bytes: 256