akhauriyash/Code-Regression huggingface dataset:
W, H, N = gets.split.map(&:to_i)
minX = 0
minY = 0
maxX = W
maxY = H

N.times do
    x, y, a = gets.split.map(&:to_i)
    case a
    when 1
        minX = x if minX < x
    when 2
        maxX = x if maxX > x
    when 3
        minY = y if minY < y
    when 4
        maxY = y if maxY > y
    end
end
ans = (maxX - minX) * (maxY - minY)
ans = 0  if maxX <= minX
ans = 0  if maxY <= minY

puts ans


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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if(n % (a + b) <= a) cout << (n / (a + b)) * a + n % (a + b) << endl;
  else cout << (n / (a + b)) * a + a << endl;
} 


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

vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    vector <int> dp(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        dp[a[i]-1]=i+1;
    }
    for(int i = 0; i < n; i++){
        cout << dp[i] << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

// dp[i][k][sum] := 先頭からi番目までの数字から k 枚選んだとき,
// 選んだ数字の総和を s にできる場合の数
long long dp[55][55][3000] = {0};

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

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

  dp[0][0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int k = 0; k <= i; k++) {
      for (int sum = 0; sum <= 2500; sum++) {
        if (i > 0 && sum - x[i-1] < 0) {
          dp[i][k][sum] = dp[i - 1][k][sum];
        }
        if (i > 0 && k > 0 && sum - x[i-1] >= 0) {
          dp[i][k][sum] = dp[i - 1][k][sum] + dp[i - 1][k - 1][sum - x[i-1]];
        }
      }
    }
  }

  long long ans = 0;
  for (int k = 1; k <= n; k++) {
    ans += dp[n][k][k * a];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 65792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int stack[200] = {};
int stackPointer = -1;

void push(int);
void add();
void subtract();
void multiply();

int main(void)
{
  int i;
  char rawinput[400];
  scanf("%[^n]s", rawinput);
  char *token = strtok(rawinput, " \n");
  while (token != NULL)
    {
      if (!strcmp(token, "+"))
	{
	  add();
	}
      else if (!strcmp(token, "-"))
	{
	  subtract();
	}
      else if (!strcmp(token, "*"))
	{
	  multiply();
	}
      else
	{
	  push(atoi(token));
	}
      token = strtok(NULL, " \n");
    }
  printf("%d\n", stack[stackPointer]);
  return 0;
}

void push(int input)
{
  stack[++stackPointer] = input;
}

void add()
{
  int addition = stack[stackPointer] + stack[stackPointer-1];
  stack[stackPointer] = 0;
  stack[--stackPointer] = addition;
}

void subtract()
{
  int subtraction = stack[stackPointer-1] - stack[stackPointer];
  stack[stackPointer] = 0;
  stack[--stackPointer] = subtraction;
}

void multiply()
{
  int multiplication = stack[stackPointer] * stack[stackPointer-1];
  stack[stackPointer] = 0;
  stack[--stackPointer] = multiplication;
}



Measured memory_bytes: 2100
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<int, int> > VPII;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	int X, A, B;
	cin >> X >> A >> B;
	X -= A;
	X %= B;
	O(X);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

const ll MOD = 1000000007;
const ll INF = 100000;
struct edge{ int from, to, cost; };
vector<edge> v[100010];
int n, m;
int x[100010];
bool visit[100010];
int main(void){
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        v[l].push_back({ l, r, -d });
        v[r].push_back({ r, l, d });
    }
    
    for (int i = 0; i < n; i++) x[i] = 0;


    for (int i = 0; i < n; i++){
        if (visit[i]) continue;
        visit[i] = true;
        queue<vector<edge>> que;
        que.push(v[i]);

        while (que.size() != 0){
            vector<edge> vert = que.front(); que.pop();
            for (int j = 0; j < vert.size(); j++){
                edge e = vert[j];
                if (!visit[e.to]){
                    x[e.to] = x[e.from] + e.cost;
                    visit[e.to] = true;
                    que.push(v[e.to]);
                
                }
                else{
                    if (x[e.to] != x[e.from] + e.cost){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << "Yes" << endl;


}

Measured memory_bytes: 18336
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		insertionSort(array, n);
		sc.close();
	}

	// 挿入ソート
	static void insertionSort(int[] a, int n) {
		showArray(a);
		for(int i = 1; i < n; i++) {
			int v = a[i];   // 挿入する要素の保存
			int j = i - 1;
			while(j >= 0 && a[j] > v) {
				a[j + 1] = a[j];
				j--;
			}
			a[j + 1] = v;
			showArray(a);
		}
	}

	static void showArray(int[] a) {
		System.out.print(a[0]);
		for(int i = 1; i < a.length; i++) {
			System.out.print(" " + a[i]);
		}
		System.out.println();
	}
}



Measured memory_bytes: 33092
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    FOR(i, 1, 50000) {
        if(floor(1.08*i) == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, r, p, c;
  int k, i, l, m, j;
  int card[50], sto[50];
  scanf("%d %d", &n, &r);
  while(n!=0 || r!=0)
    {
      for(i=0;i<n;i++)
	{
	  card[i] = n-i;
	}
      for(k=0;k<r;k++)
	{
	  scanf("%d %d", &p, &c);
	  if(p>0)
	    {
	      for(l=0;l<p-1;l++)
		{
		  sto[l] = card[l];
		}
	    }
	  for(m=0;m<c;m++)
	    {
	      card[m] = card[p-1+m];
	    }
	  for(j=0;j<p-1;j++)
	    {
	      card[c+j] = sto[j];
	    }
	}
      printf("%d\n", card[0]);
      scanf("%d %d", &n, &r);
    }
  return 0;
}

Measured memory_bytes: 600
#include<cstdio>

int graph[10][10];
int n,ans=0;

void search(int came[],int v){
  int i;
  for(i=0;i<n;i++)
    if(came[i]==0) break;
  if(i==n){
    ans++;
    return;
  }
  for(i=0;i<n;i++){
    if(graph[v][i]==1 && came[i]==0){
      came[i]=1;
      search(came,i);
      came[i]=0;
    }
  }
}

int main(void){
  int m;
  int came[10]={};

  scanf("%d %d",&n,&m);
  int a,b;
  for(int i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    graph[a-1][b-1]=1;
    graph[b-1][a-1]=1;
  }

  came[0]=1;
  search(came,0);

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

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen = 1 << 20 | 5;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1 : *ib++)
inline int read() {
  static int ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
typedef long long ll;
#define pb push_back
#define rez resize
#define ppp pop_back
template <typename T> inline void exgcd(T a, T b, T &x, T &y) {
  if (!b) { x = 1, y = 0; return; }
  exgcd(b, a - a / b * b, y, x), y -= a / b * x;
}
namespace modular {
  const int mod = 998244353;
  int ret;
  inline int add(int a, int b) { return a < mod - b ? a + b : a - mod + b; }
  inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; }
  inline int mul(int a, int b) { return (ll) a * b % mod; }
  inline void Add(int &a, int b) { a = a < mod - b ? a + b : a - mod + b; }
  inline void Dec(int &a, int b) { a = a < b ? a - b + mod : a - b ; }
  inline void Mul(int &a, int b) { a = (ll) a * b % mod; }
  inline int ksm(int a, int p) { for (ret = 1; p; p >>= 1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1); return ret; }
  inline int fix(int x) {
    x <= -mod || x >= mod ? x %= mod : 0;
    return x < 0 ? x + mod : x;
  }
  inline int Inv(int a) {
    static int x, y;
    return exgcd(a, mod, x, y), fix(x);
  }
}  using namespace modular;
const int N = 1e6 + 5;
int ss[N], mu[N], F[N], pri[N / 10], tot = 0, cnt[N], n, mx = 0;
bool vs[N];
inline void init() {
  mu[1] = 1;
  for (ri i = 2; i <= mx; ++i) {
    if (!vs[i]) pri[++tot] = i, mu[i] = mod - 1;
    for (ri j = 1; j <= tot && i * pri[j] <= mx; ++j) {
      vs[i * pri[j]] = 1;
      if (i == i / pri[j] * pri[j]) {
        mu[i * pri[j]] = 0;
        break;
      }
      mu[i * pri[j]] = mu[i] ? mod - mu[i] : 0;
    }
  }
  for (ri i = 1, t; i <= mx; ++i) {
    t = mul(mu[i], i);
    for (ri j = 1; j * i <= mx; ++j) Add(F[i * j], t);
    Mul(F[i], i);
  }
}
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = read();
  int res = 0;
  for (ri i = 1, x; i <= n; ++i) {
    mx = max(mx, x = read());
    ++cnt[x], Dec(res, x);
  }
  init();
  for (ri ss, i = 1; i <= mx; ++i) {
    ss = 0;
    for (ri j = 1; j * i <= mx; ++j) Add(ss, mul(cnt[j * i], j));
    Add(res, mul(F[i], mul(ss, ss)));
  }
  cout << mul(res, (mod + 1) >> 1);
  return 0;
}

Measured memory_bytes: 17588
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const double EPS = 1e-10;

int main(void)
{
    int x;
    cin >> x;

    if (x >= 30)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }

    // cout << ans << endl;
    return (0);
}

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

ifstream fin("pentagon.in");
ofstream fout("pentagon.out");

#define MOD 100019
#define NMAX 100005

int main()
{
   int n;
   int v[105];
   cin>>n;

   double maxim = 0;
   int poz = 0;

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


   int ans = 1000000000;
   for(int i=1;i<=100;i++)
   {
      int cost = 0;
      for(int j=1;j<=n;j++)
         cost+= (v[j] - i) * (v[j] - i);
      ans = min(ans,cost);
   }
   cout<<ans;

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    int n;std::cin>>n;
    int ans=0;
    for(;n>0;n-=++ans);
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 256
def do_match(A: list, B: list, offsets: tuple, size_B: int) -> bool:
    oh, ow = offsets
    for h in range(size_B):
        for w in range(size_B):
            if A[oh + h][ow + w] != B[h][w]:
                return False
    return True


def template_matching(N: int, M: int, A: list, B: list) -> bool:
    for offset_h in range(N - M + 1):
        for offset_w in range(N - M + 1):
            if do_match(A, B, (offset_h, offset_w), M):
                return True
    return False


if __name__ == "__main__":
    N = 0
    M = 0
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    yes = template_matching(N, M, A, B)
    print('Yes' if yes else 'No')


Measured memory_bytes: 3064
import java.util.List;
import java.util.Scanner;

public class Main {
	static int v = 0;
	static List<List<Integer>> ansList = null;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		System.out.println(0);
		String first = sc.next();

		int start = 1;
		int end = n - 1;

		while (start <= end) {
			int mid = (end + start + 1) / 2;
			System.out.println(mid);
			String s = sc.next();
			if ("Vacant".equals(s)) {
				sc.close();
				return;
			}

			if (first.equals(s)) {
				if (mid % 2 == 0) {
					start = mid;
				} else {
					if (end == mid) {
						end = mid - 1;
					} else {
						end = mid;
					}
				}
			} else {
				if (mid % 2 == 0) {
					if (end == mid) {
						end = mid - 1;
					} else {
						end = mid;
					}
				} else {
					start = mid;
				}
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 24356
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){

  int n;
  cin >> n;
  FINA(n * (n+1) / 2);

 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
string s;
char c;
int main(){
    cin>>a>>s>>b;
    c=s[b-1];
    for(int i=0;i<a;i++)if(s[i]==c)cout<<c;
    else cout<<'*';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vel vector<long long>
#define vech vector<char>
#define ves vector<string>
#define veb vector<bool>
#define vvel vector<vel>
#define vvech vector<vech>
#define int long long
#define pin pair<int,int>
#define ppin pair<int,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define maxel(vec, j) *max_element(vec.begin(), vec.begin()+j)

using namespace std;
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
int vsum(vel v){ return accumulate(v.begin(), v.end(), 0); }
int msum(vvel v){
    int ans = 0;
    rep(i, v.size()){
        ans += vsum(v[i]);
    }
    return ans;
}
signed main() {
    int pr = 1000;
    pr *= pr * pr; pr += 7;
    int P, Q, R;
    cin >> P;
    cin >> Q;
    cin >> R;
    cout<<P+Q+R - max(max(P, Q), R);
    return 0;
}
/*
7 1 3 7 6
.#..#..
 */


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[]){
    std::string number;
    std::cin >> number;
    int nOrder = number.size();
    int order = 1;
    int nOddOrderNum = 0;
    for(int i=0; (i<<1)+1<nOrder; i++){
        nOddOrderNum += 9*order;
        order *= 100;
    }
    if((nOrder&1) == 1){
        nOddOrderNum += atoi(number.c_str())-order+1;
    }
    std::cout << nOddOrderNum << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
class Main{
    public static void main(String []args){
        Scanner sc=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int n=sc.nextInt();
        int a[][]=new int[n][60];
        for (int i = 0; i <n ; i++) {
            long num=sc.nextLong();
            for (int j = 0; j <60 ; j++) {
                if((num&(1l<<j))>0){
                    a[i][j]=1;
                }
            }
        }

        long ans=0,mod=1000000007;
        for (int i = 0; i <60 ; i++) {
            int c0=0,c1=0;
            for (int j = 0; j <n ; j++) {
                if(a[j][i]==0)c0++;
                else c1++;
            }
            ans=(ans+((1l*c0*c1)%mod*((1l<<i)%mod))%mod)%mod;
          //  out.println(i+" "+(c0*c1)+ " "+c0+" "+c1);
        }
        out.println(ans);
        out.close();
    }
}

Measured memory_bytes: 182548
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;
ll a[3005];
int main()
{
	int n;
	ll b=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		b=b+a[i]-1;
	}
	printf("%lld\n",b);
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[0]!=s[2] && s[2]==s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long W, long long H, long long x, long long y){
  int f=0;
  if(W%2==0&&H%2==0&&W/2==x&&H/2==y){
    f=1;
  }
  cout<<(double)W*(double)H/2.0L<<" "<<f<<endl;
}

int main(){
    long long W;
    scanf("%lld",&W);
    long long H;
    scanf("%lld",&H);
    long long x;
    scanf("%lld",&x);
    long long y;
    scanf("%lld",&y);
    solve(W, H, x, y);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#define int long long
#define PII pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') { if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar();}
	return f==1?x:-x;
}
inline void print(int x){
	if(x<0) x=~x+1,putchar('-');
	if(x>=10) print(x/10);
	putchar((x%10)|48);
}
priority_queue<PII,vector<PII>,greater<PII> >Q;
int n;
int m;
int cnt[100010];
int tmp[100010];
vector<int>vec[200010];
int fac[100010],ifac[100010];
int R[200010];
int a[200010],b[200010];
int x=1,len;
const int mod=998244353;
int num;
int qpow(int x,int k){
	int res=1;
	while(k){
		if(k&1) res=1ll*res*x%mod;
		x=1ll*x*x%mod;
		k>>=1;
	}
	return res; 
}
inline int C(int x,int y){
	if(x==0||y==0) return 1;
	return 1ll*fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}
void NTT(int s[],int f){
	for(int i=0;i<=x;i++) if(i<R[i]) swap(s[i],s[R[i]]);
	for(int l=1;l<x;l<<=1){
		int w;
		if(f==1) w=qpow(3,(mod-1)/(l<<1));
		else w=qpow(qpow(3,mod-2),(mod-1)/(l<<1));
		for(int j=0;j<x;j+=(l<<1)){
			int sum=1;
			for(int k=0;k<l;k++){
				int a1=s[j+k],a2=sum*s[j+l+k]%mod;
				s[j+k]=(a1+a2)%mod,s[j+l+k]=(a1-a2+mod)%mod;
				sum=sum*w%mod;
			}
		}
	}
}
signed main(){
	n=read();
	n<<=1;
	fac[1]=1;
	fac[0]=1;
	for(int i=2;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
//	printf("%d %d %d %d\n",ifac[1],ifac[2],ifac[3],ifac[4]);
//	printf("%d %d\n",C(2,1),C(1,1));
//	printf("%d\n",ifac[1]);
	for(int i=1;i<=n;++i) tmp[i]=read();
	sort(tmp+1,tmp+n+1);
	for(int i=1;i<=n;++i){
		if(tmp[i]!=tmp[i-1]) cnt[++m]=1;
		else ++cnt[m];
	}
	for(int i=1;i<=m;++i){
		for(int j=0;j<=(cnt[i]>>1);++j){
			vec[i].pb(1ll*C(cnt[i],j)*C(cnt[i]-j,j)%mod*fac[j]%mod*qpow(qpow(2,j),mod-2)%mod);
//			printf("i:%d,j:%d,cnt:%d,v:%d\n",i,j,cnt[i],vec[i][j]);
//			printf("%d %d %d %d\n",C(cnt[i],j),C(cnt[i]-j,j),fac[j],qpow(2,j));
		}
		Q.push(mp(vec[i].size(),i));
	}
	num=m;
	int ans=0;
	while(Q.size()>1){
		int u=Q.top().se;
		Q.pop();
		int v=Q.top().se;
		Q.pop(); 
		int N=vec[u].size(),M=vec[v].size();
		x=1,len=0;
		while(x<=N+M-2) x<<=1,len++; 
		for(int i=0;i<=x;i++) R[i]=(R[i>>1]>>1)|((i&1)<<len-1);
		for(int i=0;i<=x;++i) a[i]=b[i]=0;
		for(int i=0;i<N;++i) a[i]=vec[u][i];
		for(int i=0;i<M;++i) b[i]=vec[v][i];
		NTT(a,1),NTT(b,1);
		for(int i=0;i<=x;i++) a[i]=1ll*a[i]*b[i]%mod;
//		printf("u:%d,v:%d\n",u,v);
//		for(int i=0;i<=N+M-2;++i) printf("%d\n",1ll*a[i]*qpow(x,mod-2)%mod);
		NTT(a,-1);
		++num;
		if(!Q.size()){
//			ans=1ll*C(n,n>>1)*fac[n>>1]%mod*qpow(qpow(2,n>>1),mod-2)%mod;
			for(int i=0;i<=N+M-2;++i) (ans+=qpow(-1,i)*a[i]*qpow(x,mod-2)%mod*C(n-2*i,(n-2*i)>>1)%mod*fac[(n-2*i)>>1]%mod*qpow(qpow(2,(n-2*i)>>1),mod-2)%mod)%=mod;
			break ;
		}
		for(int i=0;i<=N+M-2;++i) vec[num].pb(1ll*a[i]*qpow(x,mod-2)%mod);
		Q.push(mp(vec[num].size(),num));
	}
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 21508
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,_N=N;I<_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
int main() {
  R(N)RL(dummy);RL(S)RL(T);
  int stat = 0,nstat;
  i8t table[3][3] = {
    {1,3,6},
    {1,2,2},
    {1,1,3},
  };
  i8t a=1;
  i8t mod=1000000007;
  for(int i = 0;i<N;i++){
    if(S[i]==T[i]){
      nstat=1;
    }else{
      nstat=2;
      i++;
    }
    a=a*table[stat][nstat]%mod;
    stat=nstat;
  }
  P(a);
  return 0;
}

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

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for (int i = 0; i < n; ++i)
		std::cin >> a[i];
	for (int i = n - 1; i > 0; --i)
		std::cout << a[i] << ' ';
	std::cout << a[0] << std::endl;
	return 0;
} 



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  string S;
  cin>>S;
  int ans=1;
  rep(i,S.size()){
    if(i%2==0){
      if(S[i]=='L') ans=0;
    }else if(S[i]=='R') ans=0;
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}






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

X = []
cost = []
stock = []

for i in range(n):
  x = list(map(int, input().split()))
  X.append(x)

X.sort()
price, stock = zip(*X)

accumulated = []
accumulated.append(0)

for i in range(n):
  accumulated.append(accumulated[i] + stock[i])

bought = 0
cost = 0
i = 0

while bought + stock[i] < m:
  bought += stock[i]
  cost += price[i] * stock[i]
  i += 1

print(cost + (m - accumulated[i]) * price[i])

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

int main()
{
    int a,b;
    string s,t,u;
    cin>>s>>t>>a>>b>>u;
    int x=(a-1);
    int y=(b-1);
    if(u==s)
    {

        cout<<x<< ' '<<b<<endl;
    }
    else
    {

        cout<<a<<' '<<y<<endl;
    }


}












Measured memory_bytes: 3628
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

N = int(input())
A = 0
BA = 0
B = 0
Z = 0
ans = 0

for _ in range(N):
    s = input()
    ans += s.count("AB")
    if s[0] == "B":
        if s[-1] == "A":
            BA += 1
        else:
            B += 1
    elif s[-1] == "A":
        A += 1

if BA:
    ans += (BA - 1)
    if A:
        A -= 1
        ans += 1
    if B:
        B -= 1
        ans += 1

ans += min(A, B)
print(ans)

Measured memory_bytes: 3572
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using usize = std::size_t;
using u64 = std::uint64_t;

static constexpr u64 mod = 1000000007;

int main() {
  std::string t, p;
  std::cin >> t >> p;
  const usize n = t.size();

  bool flag = true;

  const auto match = [&]() {
    std::vector<bool> v(n, false);
    usize i = 0;
    for (const auto c : p) {
      while (i != n && t[i] != c) {
        i += 1;
      }
      if (i == n) {
        flag = false;
        break;
      }
      v[i] = true;
      i += 1;
    }
    return std::move(v);
  };

  auto f = match();
  if (!flag) {
    std::cout << "no\n";
    return 0;
  }
  std::reverse(t.begin(), t.end());
  std::reverse(p.begin(), p.end());
  auto b = match();
  std::reverse(b.begin(), b.end());

  for (usize i = 0; i != n; ++i) {
    if (f[i] != b[i]) {
      std::cout << "no\n";
      return 0;
    }
  }
  std::cout << "yes\n";

  return 0;
}


Measured memory_bytes: 4252
#include<stdio.h>
int N, K, H[100000], min, i, j;

int med3(int x, int y, int z);
void quickSort(int a[], int left, int right);
void sort(int a[], int size);

int main(){
	scanf("%d%d", &N, &K);
	for(i=0; i<N; i++){
		scanf("%d", &H[i]);
	}
	sort(H, N);
	min = H[N-1] - H[1];
	for(i=K; i<=N; i++){
		j = H[i-1] - H[i-K];
		if(j<min){min=j;}
	}
	printf("%d\n", min);
}

int med3(int x, int y, int z){
	if(x < y){
		if (y < z){return y;}else if(z < x){return x;}else{return z;}
	} else {
		if (z < y){return y;}else if(x < z){return x;}else{return z;}
	}
}

void quickSort(int a[], int left, int right){
	if(left >= right){return;}
	int pivot = med3(a[left], a[left+(right-left)/2], a[right]);
	int l=left, r=right;
	while(1){
		while (a[l] < pivot){l++;}
		while (pivot < a[r]){r--;}
		if(l>=r){break;}
		int t=a[l]; a[l]=a[r]; a[r]=t;
		l++; r--;
	}
	quickSort(a, left, l-1);
	quickSort(a, r+1, right);
}

void sort(int a[], int size){
	quickSort(a, 0, size-1);
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
int *cat;
struct hh{
	int digit,look;
}temp[3];
int main ()
{
	int i,j,n,k,error;
	while(scanf("%d",&n)!=EOF)
	{
		cat=(int*)malloc(n*sizeof(int));
		error=0;k=0;
		for(i=0;i<3;i++){
			temp[i].digit=0;
			temp[i].look=0;
		}
		for(i=0;i<n;i++){
			scanf("%d",&cat[i]);

			if(k==0){
			temp[0].look=cat[i];
			temp[0].digit++;
			k++;			
		}
		else{
			if(cat[i]==temp[0].look)
				temp[0].digit++;
			else{
				if(temp[1].look!=0&&temp[1].look!=cat[i])
					error++;
				else{
					temp[1].look=cat[i];
					if(temp[0].look-cat[i]<-1||temp[0].look-cat[i]>1)
						error++;
					temp[1].digit++;
					k=2;
				}
			}		
		}	
		}	
		if(error!=0){
			printf("No\n");
			continue;
		}
		if(temp[1].digit==0)
		{
			if(n==temp[0].look+1)
				printf("Yes\n");
			else if(n>=(temp[0].look*2))
				printf("Yes\n");
			else
				printf("No\n");
		}
		else{
			if(temp[0].look>temp[1].look){
				if(n>=(temp[0].look*2-temp[1].digit)&&temp[1].digit<=temp[0].look-1)
					printf("Yes\n");
				else
					printf("No\n");
			}
			else{
					if(n>=(temp[1].look*2-temp[0].digit)&&temp[0].digit<=temp[1].look-1)
					printf("Yes\n");
				else
					printf("No\n");
			}
		}
		free(cat);
	}
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        if (30 <= X) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

//????¬??????§?????£???????????°????±???????
int coin(int X){
    int ans = 0;
    //500
    ans = X / 500;

    //100
    ans = ans + (X % 500) / 100;

    //50
    ans = ans + ((X % 500) % 100) / 50;

    //10
    ans = ans + (((X % 500) % 100) % 50) / 10;

    //5
    ans = ans + ((((X % 500) % 100) % 50) % 10) / 5;

    //1
    ans = ans + (((((X % 500) % 100) % 50) % 10) % 5);

    return  ans;
}

int main(void){

    int i = 0;
    int ans[5];
    int input;
    while(1){
        cin >> input;
        if(input == 0){ break;}
        else{
            ans[i] = coin(1000-input);
        }
        i++;
    }

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

    return 0;
}

Measured memory_bytes: 3080
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto n = sread();
    // writeln(n);
    long ans;
    foreach (i; 0 .. (n.length))
    {
        ans += n[i] - '0';
    }
    if (ans % 9 == 0)
    {
        writeln("Yes");
    }
    else
    {
        writeln("No");
    }
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3740
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <queue>
using namespace std;
int main() {
	int K,N;
	cin >> N>>K;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	sort(p.begin(), p.end());
	int ans=0;
	for (int i = 0; i < K; i++) {
		ans += p[i];
	}
	cout << ans;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};

int arr[MAXN];

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d", &n);

    bool has = false;
    int cur = 1;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        if (arr[i] != cur) {
            ans++;
        } else {
            cur++;
            has = true;
        }
    }
    if (!has)
        printf("-1");
    else
        printf("%d", ans);

    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    string s; cin >> s;

    auto f = [&](char c) {
        for (auto &si: s) {
            if (si == c) {
                return false;
            }
        }
        return true;
    };

    for (char c = 'a'; c <= 'z'; ++c) {
        if (f(c)) {
            cout << c << "\n";
            return 0;
        }
    }

    cout << "None" << "\n";

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int a[3][3];
    bool flag=false;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int n;
    vector<vector<bool>>d(3,vector<bool>(3));
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        for(int i=0;i<3;i++)
        for(int j=0;j<3;j++){
            if(a[i][j]==x)d[i][j]=true;
        }
    }
    for(int i=0;i<3;i++){
        if(d[i][0]&&d[i][1]&&d[i][2])flag=true;
    }
    for(int i=0;i<3;i++){
        if(d[0][i]&&d[1][i]&&d[2][i])flag=true;
    }
    if(d[0][0]&&d[1][1]&&d[2][2])flag=true;
    if(d[2][0]&&d[1][1]&&d[0][2])flag=true;
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<map>
#include<cctype>
#include<sstream>
using namespace std;
#define N 1000000000
int gcd(int x)
{
	int ans = 0;
	for (int i = 1;i <= x;i++)
	{
		if (x%i == 0)
			ans++;
	}
	return ans;
}
int main()
{
	int n;
	while (cin>>n)
	{
		int ans=0;
		for (int i = 1;i <= n;i++)
		{
			if (gcd(i) == 8 && i%2==1)
				ans++;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

const int N = 2e5+5;

stack<ll>s[N];
set<ll>t; // set of top elements
map<ll,ll>mp; // on which stack is the topmost element present

void solve()
{
       ll n; cin>>n;
       //ll a[n];
       ll cur=1;
       rep(i,0,n)
       {
              ll x; cin>>x;
              if(t.find(x-1)!=t.end())
              {
                     s[mp[x-1]].push(x);
                     mp[x]=mp[x-1];
                     t.erase(x-1);
                     t.insert(x);
              }
              else
              {
                     cur++;
                     mp[x]=cur;
                     s[cur].push(x);
                     t.insert(x);
              }
       }
       ll mx=0;
       rep(i,0,cur+1) mx=max(mx, sz(s[i]));
       cout<<n-mx;

}


int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


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

typedef long long ll;

int main(){
    char c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    printf("%c%c%c",c[0][0],c[1][1],c[2][2]);
    return 0;
}

Measured memory_bytes: 256
while True:
    a,b = input().split()
    h=int(a)
    w=int(b)
    if h ==0 and w==0:
        break
    else:
        print(w*"#")
        if h>=3 and h>=3:
            for i in range(h-2):
                print(1*"#"+(w-2)*"."+1*"#")

            print(w * "#")
        elif h==2:
            print(w * "#")
        print("")

Measured memory_bytes: 7612
# coding: utf-8
# Your code here!
n,T=map(int,input().split())
ans=1001
for i in range(n):
    c,t=map(int,input().split())
    if(t<=T and ans>c):
        ans=c
if (ans==1001):
    print("TLE")
else:
    print(ans)

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

int main(){
	string str,ans;
	int n;
	while(cin>>str){
		ans="";
		for(int i=0;i<str.size();i++){
			if(str[i]=='@'){
				n=str[i+1]-'0';
				for(int j=0;j<n;j++){
					ans+=str[i+2];
				}
				i+=2;
			}
			else ans+=str[i];
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
 
#define int long long
 
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
 
using namespace std;
 
int N, A[200005];
 
signed main() { 
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        A[i] -= i + 1;
    }
    sort(A, A + N);
 
    int b = A[N / 2];
 
    int ans = 0;
    REP(i, N) { ans += abs(A[i] - b); }
    cout << ans << endl;
 
    return 0;
}

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

#define MOD 1000000007

long *fac, *finv, *inv;

void init(int n){
	fac = malloc(sizeof(long) * (n + 1));
	finv = malloc(sizeof(long) * (n + 1));
	inv = malloc(sizeof(long) * (n + 1));
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < n; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

long combination(int n, int k){
	if(n < k)return 0;
	if(n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
	int n, k;
	long res;
	scanf("%d %d", &n, &k);
	init(n);

	for(int i = 1; i <= k; i++){
		res = combination(k - 1, i - 1) * combination(n - k + 1, i) % MOD;
		printf("%ld\n", res);
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    long long ans=0,small,large;
    int divnum=1E9+7;
    for(long long i=K; i<=N+1; i++){
        small=i*(i-1)/2;
        large=N*i-small;
        ans+=large-small+1;
        ans%=divnum;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,i,j,sum=0;
    cin>>n>>m;
    ll a[m+5];
    for(i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)
        cout<<"-1"<<endl;
    else
        cout<<n-sum<<endl;
    return 0;

}


Measured memory_bytes: 3708
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <set>
using namespace std;
class sai
{
    public :
    int ue;
    int tem;
    int migi;
    int hidari;
    int oku;
    int sita;
    void roll(char c){
        int kari;
        if (c == 'S') {
        kari = ue;
        ue = oku;
        oku = sita;
        sita = tem;
        tem = kari;
    } else if (c == 'N') {
        kari = ue;
        ue = tem;
        tem = sita;
        sita = oku;
        oku = kari;
    } else if (c == 'E') {
        kari = ue;
        ue = hidari;
        hidari = sita;
        sita = migi;
        migi = kari;
    } else if (c == 'W') {
        kari = ue;
        ue = migi;
        migi = sita;
        sita = hidari;
        hidari = kari;
    }
  
    }
};
sai roll(sai b, char c) {
    if (c == 'S') {
        b = {b.oku,b.ue,b.migi,b.hidari,b.sita,b.tem};
    } else if (c == 'N') {
        b = {b.tem,b.sita,b.migi,b.hidari,b.ue,b.oku};
    } else if (c == 'E') {
        b = {b.hidari,b.tem,b.ue,b.sita,b.oku,b.migi};
    } else if (c == 'W') {
        b = {b.migi,b.tem,b.sita,b.ue,b.oku,b.hidari};
    }
    return b;
}
bool judge(sai a, sai b) {
    bool hey = true;
    string s = "EEEENEEEENEEEENEEEENENEEENNEEEE" ;
    for (int i = 0; i < s.length(); i++) {
        if (a.oku == b.oku and a.ue == b.ue and a.migi == b.migi and a.hidari == b.hidari and a.sita == b.sita and a.tem == b.tem) {
            hey = true;
            break;
        } else {
            hey = false;
        }
        b.roll(s[i]);
    }
    return hey;
}

int main(void){
    int a1,a2,a3,a4,a5,a6,n,b1,b2,b3,b4,b5,b6;
    int x ,y;
    int ans = 999;
    string s = "EEEENEEEENEEEENEEEENENEEENNEEEE";
    cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6 ;
    cin >> b1 >> b2 >> b3 >> b4 >> b5 >> b6 ;
    sai a = {a1,a2,a3,a4,a5,a6};
    sai b = {b1,b2,b3,b4,b5,b6};
    cin >> n;
    if(judge(a,b)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
import sys
def 解():
    iN = int(input())
    aS = [_.rstrip() for _ in sys.stdin.readlines()]

    def buildDic(s):
        d = {}
        for es in s:
            if es in d:
                d[es] += 1
            else:
                d[es] = 1
        return d


    d0 = buildDic(aS[0])
    for s in aS[1:]:
        ed = buildDic(s)
        for ts in ed:
            if ts in d0:
                i = min(d0[ts],ed[ts])
                if i :
                    d0[ts]=i
                else:
                    del d0[ts]
        for ts in set(d0.keys()) - set(ed.keys()):
            del d0[ts]

        if len(d0) == 0 :
            print("")
            exit()
    aNS = sorted(d0.keys())
    sR = ""
    for ts in aNS:
        sR += ts * d0[ts]
    print(sR)
解()



Measured memory_bytes: 3064
import sys
input=sys.stdin.buffer.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
N = int(input())
n = int(N**(0.5))
for i in range(n):
  c = n-i
  if N % c == 0:
    a = N/c
    break;
print(int(a+c-2))

Measured memory_bytes: 40044
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 
 
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}
const ll M  = 100005;
vector<int> adj[M];
int visited[M];
int dp[M];
void dfs(int i)
{
    visited[i] = 1;
    rep(j, adj[i].size())
    {
        if(!visited[adj[i][j]])
            dfs(adj[i][j]);
        dp[i] = max(dp[i], dp[adj[i][j]]+1);
    }
}
 
 
int main() {
    #ifdef sharma
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);      
    #endif
    fastio;
    int n, m;
    cin >> n >> m;
    
    while(m--)
    {
        int x, y;
        cin >> x >> y;
        adj[x].pb(y);
    }
    rep(i, n+1)
    dfs(i);
    int res = 0;
    rep(i, n+1)
    {
        res = max(res, dp[i]);
    }
    cout << res;
    return 0; 
}

Measured memory_bytes: 8576