akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    int maxp = (n - 1) * (n - 2) / 2;
    if (k > maxp) {
        printf("-1\n");
    } else {
        int diff = maxp - k;
        int e = (n - 1) + diff;
        printf("%d\n", e);
        for (int i = 2; i <= n; i++) {
            printf("%d %d\n", 1, i);
        }
        for (int i = 2; i <= n && diff > 0; i++) {
            for (int j = i + 1; j <= n && diff > 0; j++) {
                printf("%d %d\n", i, j);
                diff--;
            }
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  char op;
  
  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op ==  '?'){
      break;
    }
    if(op == '+'){
      printf("%d\n",a+b);
    }
    if(op == '-'){
      printf("%d\n",a-b);
    }
    
    if(op == '*'){
      printf("%d\n",a*b);
    }
    if(op == '/'){
      printf("%d\n",a/b);
    }
  }
  return(0);
}


Measured memory_bytes: 2032
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a=0;
    char s[5];
    
    scanf("%s", s);
    rep(i, 4){
        if (s[i]=='+') {
            a++;
        } else {
            a--;
        }
    }
    
    printf("%d", a);
    
    return 0;
}



Measured memory_bytes: 1724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();

		double r = Double.parseDouble(str);

		double circ = (2 * Math.PI * r);
		double are = (Math.PI * r * r);

		System.out.printf("%f %f\n",are ,circ);
	}
}

Measured memory_bytes: 16988
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    ll a = 0, b = 0, c = 0, x = 0, y = 0;
    cin >> a >> b >> c >> x >> y;
    if (x == y) {
        cout << min(a+b, c*2) * x << endl;
    }
    else if (x < y) {
        cout << min(a+b, c*2) * x + min(b, c*2) * (y-x) << endl;
    }
    else {
        cout << min(a+b, c*2) * y + min(a, c*2) * (x-y) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    int ans=0;
    for(int i=0;i<(1<<3);i++){
        int sum=a;
        if((1<<2)&i)sum+=b;
        else sum-=b;

        if((1<<1)&i)sum+=c;
        else sum-=c;
        
        if((1<<0)&i)sum+=d;
        else sum-=d;

        if(sum==7){
            ans=i;
            break;
        }
    }

    string exp="";

    exp+=a+'0';
    if((1<<2)&ans)exp+="+";
    else exp+="-";
    
    exp+=b+'0';
    if((1<<1)&ans)exp+="+";
    else exp+="-";
    
    exp+=c+'0';
    if((1<<0)&ans)exp+="+";
    else exp+="-";

    exp+=d+'0';
    exp+="=7";

    cout << exp << endl;

    return 0;
}


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

int main() {
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    string s, t;
    cin >> s >> t;
    int ls, lt;
    for (int i = s.size() - 1; i >= 0; i--) {
      if (s[i] == '1') {
        ls = i;
        break;
      }
    }
    for (int i = t.size() - 1; i >= 0; i--) {
      if (t[i] == '1') {
        lt = i;
        break;
      }
    }
    int r = ls;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != t[i]) {
        r = i;
        break;
      }
    }
    cout << abs(ls - r) + abs(lt - r) << endl;
  }
}



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

int main(){
  int s;
  string se;
  cin >> s;
  se=to_string(s);

  for(int i=0;i<3;++i){
    if(se[i]==se[i+1]){
      cout << "Bad";
      return 0;
    }
    }
    cout << "Good";
    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int x,y;
    cin>>x>>y;
    if(x==2&&y==2){
      cout<<"Yes"<<endl;
    }else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)){
      cout<<"Yes"<<endl;
    }else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12)){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long n, a[10009], sum1, sum2, max1 = -(1 << 30), max2 = -(1 << 30); bool used[10009];
vector<long long>ans;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		if (i % 2 == 1) { sum1 += max(0LL, a[i]); max1 = max(max1, a[i]); }
		if (i % 2 == 0) { sum2 += max(0LL, a[i]); max2 = max(max2, a[i]); }
	}
	if (max1 < 0) sum1 = max1;
	if (max2 < 0) sum2 = max2;
	if (sum1 > sum2) {
		int cnt = 0;
		for (int i = 1; i <= n; i += 2) {
			if (a[i] >= 0) { used[i] = true; cnt++; }
		}
		if (max1 < 0) {
			for (int i = 1; i <= n; i += 2) {
				if (a[i] == max1) { used[i] = true; cnt++; break; }
			}
		}
	}
	else {
		int cnt = 0;
		for (int i = 2; i <= n; i += 2) {
			if (a[i] >= 0) { used[i] = true; cnt++; }
		}
		if (max2 < 0) {
			for (int i = 2; i <= n; i += 2) {
				if (a[i] == max2) { used[i] = true; cnt++; break; }
			}
		}
	}
	int F = n, L = 1, R = n;
	for (int i = 1; i <= n; i++) { L = i; if (used[i] == true) break; ans.push_back(1); F--; }
	for (int i = n; i >= 1; i--) { R = i; if (used[i] == true) break; ans.push_back(F); F--; }
	for (int i = L + 2; i <= R; i += 2) {
		if (used[i] == true) ans.push_back(2);
		if (used[i] == false) ans.push_back(3);
	}
	cout << max(sum1, sum2) << endl;
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++) cin >> A.at(i);
    int sum = 0;
    for (int i=0; i<N; i++) sum += A.at(i);
    cout << sum - N << endl;
}

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

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

	int num = 0;
	for(int i = 1; i <= n; ++i) {
		string str = to_string(i);
		if(str.size() % 2 == 1) ++num;
	}

	cout << num << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 long COM(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() {
    // 前処理
    COMinit();

    // 計算例
    //cout << COM(100000, 50000) << endl;
    int n,k;
    cin >> n >> k;
    vector<long> a(n);
    rep(i,n) cin >> a.at(i);
    sort(all(a));
    long long ans = 0;
    rep(i,n){
        long tmp = a.at(i);
        long long maxi = COM(i,k-1);
        long long mini = COM(n-1-i,k-1);
        ans += maxi*tmp - mini*tmp + MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		sc.close();

		String[] lines = line.split(" ");
		int a = Integer.parseInt(lines[0]);
		int b = Integer.parseInt(lines[1]);
		int c = Integer.parseInt(lines[2]);

		if ((a + b) >= c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22228
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc060.contest.atcoder.jp/tasks/arc060_b>
問題文============================================================
 2 以上の整数 b および 1 以上の整数 n に対し、関数 f(b,n) を次のように定義します。
 
 n<b のとき f(b,n)=n
 n≥b のとき f(b,n)=f(b, floor(n⁄b))+(n mod b)
 ここで、floor(n⁄b) は n⁄b を超えない最大の整数を、 n mod b は n を b で割った余りを表します。
 
 直感的に言えば、f(b,n) は、n を b 進表記したときの各桁の和となります。 例えば、
 
 f(10, 87654)=8+7+6+5+4=30
 f(100, 87654)=8+76+54=138
 などとなります。
 
 整数 n と s が与えられます。 f(b,n)=s を満たすような 2 以上の整数 b が存在するか判定してください。
 さらに、そのような b が存在するならば、その最小値を求めてください。
 

 1≤n≤10^11
 1≤s≤10^11
 n, s はいずれも整数である
=================================================================

解説=============================================================

 制約、式から色々と考えていると
 b > √n の時
     n = p*b + q
 と表すことができる
 ここで、
     s = p + q
 であるので
     b = (n-s)/p + 1
 と表すことができる。
 
 ここで、 b > √n より
     n = p*b + q >= p*b > p^2 => p < √n
 
 よって p を全探索すれば b は一意に定まるので O(√n)で全探索できる
 
 また b <= √n の時
 これは単純に全探索すれば良い
 
 最後に コーナーケースとして n = s の時だけ n + 1 を答える
 
================================================================
*/

ll f(ll b,ll n){
    if(n < b) return n;
    else return f(b,n/b) + n%b;
}
ll solve(){
    ll n,s; cin >> n >> s;
    if(n == s) return n + 1;
    ll res = LINF;
    for(ll b = 2; b*b <= n; b++){
        if(f(b,n) == s){
            return b;
        }
    }
    for(ll p = 1; p*p < n;p++){
        ll b = (n-s)/p + 1;
        if(b >= 2){
            if(s == f(b,n)) res = min(res,b);
        }
    }
    return res == LINF? -1 : res;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430
import sys

input = sys.stdin.readline

MOD = 10 ** 6 + 3

fact = [1]
for n in range(1, MOD):
    fact.append((fact[-1] * n) % MOD)
    # d>1 の数列を d=1 となる数列に変換する
    # MODの倍数を含む数列の積は0になるので,
    # MODの倍数を含まない区間の積が計算できればよい
    # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい

inv_fact = [-1] * MOD
inv_fact[MOD - 1] = pow(fact[-1], MOD - 2, MOD)
for n in range(MOD - 2, -1, -1):
    inv_fact[n] = ((inv_fact[n + 1] * (n + 1)) % MOD)
    # inv_factは,inv(n!)にn,n-1,...を掛けるイメージ

Q = int(input())
for _ in range(Q):
    x, d, n = map(int, input().split())

    if x == 0:
        print(0)
        continue

    if d == 0:
        print(pow(x, n, MOD))
        continue

    xd = (x * pow(d, MOD - 2, MOD)) % MOD
    if xd == 0:
        print(0)
        continue

    if MOD - xd < n:
        print(0)
        continue

    dn = pow(d, n, MOD)
    print((((fact[xd + n - 1] * inv_fact[xd - 1]) % MOD) * dn) % MOD)


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

int main(){
	long long int n,k, temp;
	cin>>n;
	k = 2;
	long long int h[n+1];
	for (int i=1;i<=n;i++)
		cin>>h[i];
	long long int dp[n+1], ind  = 1;
	dp[1] = 0;
	for (long long int i=2;i<=n;i++){
		temp = LONG_MAX;
		for (long long int j=max(ind,i-k);j<i;j++){
			temp = min(temp, dp[j] + abs(h[j] - h[i]));
		}
		dp[i] = temp;
	}
	cout<<dp[n];
}

Measured memory_bytes: 1792
/**
 * Problem: test.cpp
 * Author: babhishek21
 * Lang: C++11
 */

#include <bits/stdc++.h> // using GCC/G++
// #include "custom/prettyprint.hpp" // G++11 only
using namespace std;

static const int MOD = 1000000007;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
#define pb push_back
#define eb emplace_back
#define mp make_pair

#define debug(x) cerr << #x << " : " << x << endl;
#define whole(func, x, ...) ([&](decltype((x)) var) { return (func)(begin(var), end(var), ##__VA_ARGS__); })(x)

int a[100010], b[100010], c[100010], ans[3][2];

int main() {
  // ios_base::sync_with_stdio(false); // for fast I/O

  int n;

  cin >> n;

  for(int i=0; i<n; i++)
    cin >> a[i] >> b[i] >> c[i];

  ans[0][0] = a[0];
  ans[1][0] = b[0];
  ans[2][0] = c[0];

  for(int i=1; i<n; i++) {
    ans[0][1] = a[i] + max(ans[1][0], ans[2][0]);
    ans[1][1] = b[i] + max(ans[0][0], ans[2][0]);
    ans[2][1] = c[i] + max(ans[0][0], ans[1][0]);

    ans[0][0] = ans[0][1];
    ans[1][0] = ans[1][1];
    ans[2][0] = ans[2][1];
  }

  cout << max(ans[0][0], max(ans[1][0], ans[2][0])) << endl;

  return 0;
}

Measured memory_bytes: 1536
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e9
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0) return 0;
		vector<string> s;
		int xe[4] = { 1,-1,0,0 };
		int ye[4] = { 0,0,1,-1 };
		queue<pair<int, int>> next;
		int visited[21][21] = {};
		REP(i, h) {
			string a;
			cin >> a;
			s.push_back(a);
			REP(q, a.length()) {
				if (a[q] == '@') {
					next.push(make_pair(i, q));
					visited[i][q] = 1;
				}
			}
		}
		int ans = 1;
		while (next.empty() == false) {
			pair<int, int> now = next.front();
			next.pop();
			REP(q, 4) {
				int now_x = now.first + xe[q];
				int now_y = now.second + ye[q];
				if (now_x >= 0 && now_x < h && now_y >= 0 && now_y < w) {
					if (visited[now_x][now_y] == 0 && s[now_x][now_y] != '#') {
						visited[now_x][now_y] = 1;
						next.push(make_pair(now_x, now_y));
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3180
N=int(input())
A=["a","b","c","d","e","f","g","h","i","j"]
L=[{}for i in range(N+1)]
L[1]["a"]=1
#print(L)

for i in range(2,N+1):
    for j,k in L[i-1].items():
        for l in range(k+1):
            L[i][j+A[l]]=max(l+1,k)
#print(L[N])
ans=L[N].keys()
ans=list(ans)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 21808
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
#define debug(x) cout << #x << " = " << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

const int mx = 100005;

int N, M;
int par[mx];
bool used[mx];
vector<int> sorted;
vector<int> G[mx];

void dfs(int v){
    if(used[v])return;
    used[v] = true;
    for(int i : G[v])dfs(i);
    sorted.push_back(v);
}

void dfs2(int v, int p){
    if(used[v])return;
    used[v] = true;
    par[v] = p + 1;
    for(int i : G[v])dfs2(i, v);
}

signed main(void){

    int N, M; cin >> N >> M;
    rep(i, N + M - 1){
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
    }

    rep(i, N)dfs(i);
    reverse(all(sorted));
    vector<int> order(N);
    rep(i, N)order[sorted[i]] = i;

    rep(i, N){
        sort(all(G[i]), [&](int x, int y){
            return order[x] < order[y];
        });
    }

    memset(used, false, sizeof(used));
    dfs2(sorted[0], -1);

    rep(i, N)cout << par[i] << endl;
    return 0;

}

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

int main(void){

    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        for(int j=i+1;j<s.size();j++){
            if(s[i]==s[j]){
                cout<<"no"<<endl;
                return 0;
            }
        }
    }
    cout<<"yes"<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        List<String> sList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            sList.add(sc.nextLine());
        }
        System.out.println("AC x " + sList.stream().filter(s -> s.equals("AC")).count());
        System.out.println("WA x " + sList.stream().filter(s -> s.equals("WA")).count());
        System.out.println("TLE x " + sList.stream().filter(s -> s.equals("TLE")).count());
        System.out.println("RE x " + sList.stream().filter(s -> s.equals("RE")).count());
    }
}


Measured memory_bytes: 66372
/*input
2
aaa
aaa

*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define pb push_back 

int main() {
	int n;
	cin>>n;
	std::map<string, int> mp;
	string s[n];
	cin>>s[0];
	mp[s[0]]++;
	for(int i=1;i<n;i++)
	{
		cin>>s[i];
		mp[s[i]]++;
		if(mp[s[i]]>1||(s[i][0]!=s[i-1][s[i-1].length()-1]))
			return cout<<"No",0;
	}
cout<<"Yes";

return 0;
} 

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int K=sc.nextInt();
        
        if(N%K==0){
            System.out.println("0");
        }else{
            System.out.println("1");
        }
    }
}


Measured memory_bytes: 22868
def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ans = 0

    for i, bb in enumerate(b):
        if bb >= a[i]:
            bb -= a[i]
            ans += a[i]
            if bb >= a[i+1]:
                ans += a[i+1]
                a[i+1] = 0
            else:
                ans += bb
                a[i+1] -= bb
        else:
            ans += bb
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 19116
#include <iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if(H==0 && W==0) break;
        else{
            if(H%2==0){
                for(int i=0;i<H/2;i++){
                    if(W%2==0){
                        for(int j=0;j<W/2;j++){
                            cout << "#.";
                        }
                        cout << "\n";
                        for(int k=0;k<W/2;k++){
                            cout << ".#";
                        }
                        cout << "\n";
                    }
                    else{
                        for(int j=0;j<(W-1)/2;j++){
                            cout << "#.";
                        }
                        cout << "#\n";
                        for(int k=0;k<(W-1)/2;k++){
                            cout << ".#";
                        }
                        cout << ".\n";
                    }
                }
                
            }
            if(H%2==1){
                for(int i=0;i<(H-1)/2;i++){
                    if(W%2==0){
                        for(int j=0;j<W/2;j++){
                            cout << "#.";
                        }
                        cout << "\n";
                        for(int k=0;k<W/2;k++){
                            cout << ".#";
                        }
                        cout << "\n";
                    }
                    else{
                        for(int j=0;j<(W-1)/2;j++){
                            cout << "#.";
                        }
                        cout << "#\n";
                        for(int k=0;k<(W-1)/2;k++){
                            cout << ".#";
                        }
                        cout << ".\n";
                    }
                }
                if(W%2==0){
                    for(int j=0;j<W/2;j++){
                        cout << "#.";
                    }
                    cout << "\n";
                }
                else{
                    for(int j=0;j<W/2;j++){
                        cout << "#.";
                    }
                    cout << "#\n";
                }
                
            }
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 1120
#include<stdio.h>
int main (){
    int a,b,c,d,e,i,j,k;
    scanf("%d",&a);
    scanf("%d",&b);
    c = a+b;
    d = a-b;
    e = a*b;

    if(c>=d && c>=e){
        printf("%d",c);
    }
    else if(e>=d && e>=c){
        printf("%d",e);
    }
    else  if(d>=c && d>=e){
        printf("%d",d);
    }



}


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
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 chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char S[500000], cn[320010], *ci = cn, ct, q1[20000];
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int AS = 40010;
char* di = cn;
int dat[AS * 2];

ll tmp[40010];
void pakuri_sort(int N, ll A[]) {
	const int b = 10;
	int kazu[1 << b] = {}, kazu2[1 << b] = {};
	rep(i, N) kazu[A[i] & ((1 << b) - 1)]++;
	rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
	for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] & ((1 << b) - 1)]] = A[i];
	rep(i, N) kazu2[tmp[i] >> b & ((1 << b) - 1)]++;
	rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
	for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> b & ((1 << b) - 1)]] = tmp[i];
}

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


	int N = 0;
	while ((ct = getchar_unlocked()) >= '0') N = N * 10 + ct - '0';
	fread(S, 1, N, stdin);
	getchar_unlocked();
	fread(cn, 1, 320010, stdin);

	ll A[40010];
	ll k = 0;
	const ll tekitou = (40006ll << 32) + 1;

	int Q = getint();
	rep(j, Q) {
		char q = *ci++;
		ci++;
		if (q == '1') {
			int i = getint() - 1;
			A[k] = i + (k << 32);
			k++;
			A[k] = i + tekitou;
			k++;
			q1[j] = *ci++;
			ci++;
		}
		else {
			A[k] = getint() - 1 + (k << 32);
			k++;
			A[k] = getint() + (k << 32);
			k++;
		}
	}

	pakuri_sort(Q + Q, A);
	k = 0;
	const int ma = (1 << 20) - 1;
	int mae = 0;
	rep(i, Q + Q) {
		int a = A[i] & ma;
		if (mae != a) {
			int ima = 0;
			for (int j = mae; j < a; j++) ima |= 1 << S[j] - 'a';
			dat[k++] = ima;
			mae = a;
		}
		int b = A[i] >> 32;
		tmp[b] = k;
	}
	int ima = 0;
	for (int j = mae; j < N; j++) ima |= 1 << S[j] - 'a';
	dat[k++] = ima;

	rep(i, k) dat[i + k] = dat[i];
	auto da = dat + k - 1;
	for (auto db = dat + k * 2 - 1; da > dat; da--)* da = *db-- | *db--;

	const char a[27] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6' };

	int k2 = 0;
	rep(j, Q) {
		if (q1[j]) {
			int i = tmp[k2++] + k;
			for (dat[i] = 1 << q1[j] - 'a'; i > 1; i >>= 1) dat[i >> 1] = dat[i] | dat[i ^ 1];
			k2++;
		}
		else {
			int ret = 0;
			for (int l = tmp[k2++] + k, r = tmp[k2++] + k; l < r; l >>= 1, r >>= 1) {
				if (l & 1) ret |= dat[l++];
				if (r & 1) ret |= dat[--r];
			}
			int kotae = __builtin_popcount(ret);
			if (kotae >= 20)* di++ = '2';
			else if (kotae >= 10)* di++ = '1';
			*di++ = a[kotae];
			*di++ = '\n';
		}
	}
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 1920
x(X):-current_input(I),read_string(I,' \n','',_,X).
n(N):-x(X),number_string(N,X).
s(V,0):- writeln(V),!.
s(V,N):- 0 is N mod 3,N1 is N-1,s(V,N1).
s(V,N):- 0 is N mod 5,N1 is N-1,s(V,N1).
s(V,N):- V1 is V+N,N1 is N-1,s(V1,N1).
main:- n(N),s(0,N).


Measured memory_bytes: 81056
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define  all(v)            v.begin(), v.end()
#define  sz(x)             (long long)x.size()
#define  debug(x)          cout << #x << ':' << x << endl;
#define  rep(i,n)          for(int i = 0; i <  n ; i++)
#define  reps(i,n)         for(int i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  REMOVE(v,a)       v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb                push_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second
#define  ajs(a)            (a<0)?(-1*a):a

using namespace std;
typedef long long          ll;
typedef vector<long long>  vll;
typedef pair<ll,ll>        pll;
typedef vector<int>        vi;
const ll MOD = 1e9+7;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = { -1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = { -1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X, int Y) {return X > Y;}


ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}


const int N = 200001;
vi adj[N];



int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string s,t;cin>>s>>t;

int n = s.length();
int m = t.length();

ll ans = MOD;

for(ll i = 0; i<(n-m+1) ; i++){
	ll k = i;
	ll cnt=0;
	for(ll j = 0; j<m; j++){
		if(t[j]!=s[k]){
			cnt++;
			}
		k++;
		
		}
	ans = min(ans,cnt);
	}

cout<<ans;
}





	
	




		



Measured memory_bytes: 8296
n = int(input())
A = sorted(map(int, input().split()))
nux = A[-1]+1
ans = 0
table = [True]*nux
for i, s in enumerate(A):
    if table[s] == False:
        continue
    if i == n-1:
        ans += 1
    elif A[i+1] != s:
        ans += 1
    b = 1
    while b*s < nux:
        table[b*s] = False
        b += 1
print(ans)


Measured memory_bytes: 32212
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int k,a,b;
  cin >> k >> a >> b;
  for(int i = a; i <= b; i++){
    if(i % k == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==1)
	{
		cout<<"YES";
		return 0;
	}
	for(int i=0;i<=100;i++)
	{
		if(a*i%b==c)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
 } 

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int cost[n]={0};
  cost[0]=0;
  cost[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++){
    int prev1=abs(arr[i]-arr[i-1]);
    int prev2=abs(arr[i]-arr[i-2]);
      cost[i]=min(cost[i-1]+prev1,cost[i-2]+prev2);
    }
    cout<<cost[n-1];
  return 0;
}

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

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	vector<int> a(n,0);
	for(int &i:a){
		scanf("%d",&i);
	}
	vector<int> b(n,0);
	for(int &i:b){
		scanf("%d",&i);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	vector<int> alt(n,0);
	int i=0;
	for(int j=0;j<n;j++){
		while(i<n && a[i]<b[j]){
			i++;
		}
		alt[j]=i;
	}
	vector<int> c(n,0);
	for(int &i:c){
		scanf("%d",&i);
	}
	sort(c.begin(),c.end());
	i=0;
	long long int ans=0ll,sum=0ll;
	for(int j=0;j<n;j++){
		while(i<n && b[i]<c[j]){
			sum+=alt[i]+0ll;
			i++;
		}
		ans+=sum+0ll;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String line;
        // ????????\???
        while((line=br.readLine()) != null) {
            // ??\???????????????????§???????????????§????????????
            String[] input = line.split(" ");
            int[] in = new int[2];
            in[0] = Integer.parseInt(input[0]);
            in[1] = Integer.parseInt(input[1]);
            
            if(in[0] > in[1]) {
                System.out.println("a > b");
            } else if(in[0] < in[1]) {
                System.out.println("a < b");
            } else {
                System.out.println("a == b");
            }
            
        }
    }
}

Measured memory_bytes: 24440
#include<stdio.h>

void swap(int *a,int *b){
	int temp;
	temp=*a; *a=*b; *b=temp;
}

int main(void){
	int a[5];
	int i,j;

	scanf("%d %d %d %d %d", &a[0],&a[1],&a[2],&a[3],&a[4]);
	
	j=4;
	while(j-->0){
		for(i=4; i>0;i--)
		if(a[i-1]<a[i]) swap(&a[i-1],&a[i]);
			};

	printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);

	return (0);
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

typedef pair<ll, ll> P;

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

    vector<P> AB(N);
    rep(i, N) {
        P p;
        cin >> p.second >> p.first;
        AB[i] = p;
    }

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

    ll time = 0;
    rep(i, N) {
        time += AB[i].second;
        if (time > AB[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main() {
    int N, K;
    cin >> N >> K;
    int k1 = K/2;
    ll ans = 0;
 
    if(N < K && K <= 2*N) {
        if(K % 2 == 0) {
            ans = 1;
        }
    }
    else if(K <= N) {
        if(K % 2 == 1) {
            for(int a = K; a <= N; a += K) {
                int n = (a+N)/K - a/K;
                ans += (ll)n*n;
            }
        }
        else {
            for(int a = k1; a <= N; a += k1) {
                int n = (a+N)/K - a/K;
                ans += (ll)n*n;
            }
        }
    }
    
    cout << ans;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

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

    int N;
    cin>>N;
    vector<ll> a(N);
    rep(i,N)cin>>a[i];
    int cnt = 1;
    rep(i,N){
        if(a[i] == cnt){
            cnt++;
        }
    }
    if(cnt == 1)cout<<-1<<endl;
    else{
        cout<<N - (cnt-1)<<endl;
    }
}

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

int H, W;
int c[10][10];
int d[10][10];

int main() {
	cin >> H >> W;
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			cin >> c[i][j];
		}
	}

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

	int ans = 0;
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			int a;  cin >> a;
			if (a != -1) ans += c[a][1];
		}
	}
	cout << ans << endl;
}


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

int main()
{
    int n, k, q;
    cin >> n >> k >> q;

    vector <int> p(n + 1, k - q);
    for(int i = 1; i <= q; i++)
    {
        int element;
        cin >> element;

        p[element]++;
    }

    for(int i = 1; i <= n; i++)
    {
        cout << (p[i] > 0 ? "Yes\n" : "No\n");
    }

    return 0;
}


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

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define LL long long
#define ULL unsigned long long
#define LB lower_bound
#define MOD1 1000000007
#define MOD2 1000000009
#define int LL
int N, W;
vector<vector<int>> arr;

int solve()
{
    vector<vector<int>> dp(N+1, vector<int>(W+1, 0));

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

    return dp[N][W];
}

main()
{
    cin >> N >> W;
    arr.resize(N);

    for (int i = 0; i < N; i++)
    {
        arr[i].resize(2);
        for (int j = 0; j < 2; j++)
            cin >> arr[i][j];
    }

    cout << solve();

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  int a, b;
  cin >> a >> b;
  int za = a, zb = b;
  rep(i, 0, n - 1) {
    int c, d;
    cin >> c >> d;
    if(c > za && d > zb) {
      if((double)c / (double)za == (double)d / (double)zb) continue;
    }
    if(c < za && d < zb) {
      if((double)za / (double)c == (double)zb / (double)d) continue;
    }
    if(c == za && d == zb) continue;
    int ka = max(a, c), kb = max(b, d);
    while(ka % c != 0) ka++;
    int tp = (ka / c) * d;
    while((ka / c) * d < b) ka += tp;
    kb = (ka / c) * d;

    int kka = max(a, c), kkb = max(b, d);
    while(kkb % d != 0) kkb++;
    tp = (kkb / d) * c;
    while((kkb / d) * c < a) kkb += tp;
    kka = (kkb / d) * c;

    if(ka + kb < kka + kkb) {
      a = ka, b = kb;
    }else {
      a = kka, b = kkb;
    }
    za = c, zb = b;
  }
  cout << a + b << endl;
}


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

using namespace std;
typedef long long ll;

char s[100001];
int animal[100001];

int main(void) {
    int n;
    cin >> n;
    scanf("%s", s);

    for(int i=-1; i<2; i+=2) for(int j=-1; j<2; j+=2) {
        animal[0] = i; animal[1] = j;
        for(int k=2; k<=n; k++) {
            if((s[k-1] == 'o' && animal[k-1] == 1) || (s[k-1] == 'x' && animal[k-1] == -1)) {
                animal[k] = animal[k-2];
            }
            else {
                animal[k] = animal[k-2] * -1;
            }
        }

        if(animal[0] == animal[n]) {
            if(animal[0] == 1) {
                if((s[0] == 'o' and animal[1] == animal[n-1]) || 
                   (s[0] == 'x' and animal[1] != animal[n-1]))
                    i = j = 2;
            }
            else if(animal[0] == -1) {
                if((s[0] == 'o' and animal[1] != animal[n-1]) || 
                   (s[0] == 'x' and animal[1] == animal[n-1]))
                    i = j = 2;
            }
        }

        if(i == 1 && j == 1) return !printf("-1\n");
    }

    for(int i=0; i<n; i++) {
        animal[i] == 1 ? printf("S") : printf("W");
    }
    puts("");
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define OKawaiiKoto ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
int main()
{
    OKawaiiKoto
    ll l,r,d,cnt=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++) if(i%d==0) cnt++;
    cout<<cnt;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<algorithm>
int main(){
	int a[3];
	for(int i=0; i<3; i++)
		scanf("%d",&a[i]);
	std::sort(a,a+3);
	puts(a[0]==5 && a[1]==5 && a[2]==7?"YES":"NO");
	return 0;
}

Measured memory_bytes: 128
N, Q = gets.split.map(&:to_i)

Q.times do
  v, w = gets.split.map(&:to_i)

  if N == 1
    puts [v, w].min
    next
  end

  v -= 1
  w -= 1

  while v != w
    if v > w
      v = (v - 1) / N
    else
      w = (w - 1) / N
    end
  end

  if v == 0
    puts 1
  else
    puts v + 1
  end
end


Measured memory_bytes: 2812
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[3][110];
int a[3];
int main(){
	scanf("%s%s%s",s[0],s[1],s[2]);
	int crr=0;
	while(1){
		if(s[crr][a[crr]]==0){
			putchar('A'+crr);
			return 0;
		}
		crr=s[crr][a[crr]++]-'a';
	}
}

Measured memory_bytes: 128
import math

L = [int(input()) for i in range(5)]

total = 0
sub = 0
for i in L:
    if i % 10 == 0:
        total += i
    else:
        rest = 10 - (i % 10)
        if rest > sub:
            sub = rest
        total += math.ceil(i / 10) * 10

print(total - sub)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int NS = 1e5 + 100;
int N, m, a[NS];
typedef pair <int, int> cn;
cn z[NS];

int main() {
	ll sum = 0;
	cin >> N >> m;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(a, a + N);
	for (int i = 0; i < m; ++i) {
		cin >> z[i].first >> z[i].second;
	}
	sort(z, z + m, [](const cn &p1, const cn &p2) {
			return p1.second < p2.second;
			});
	int i = 0;
	--m;
	for (; i < N; ++i) {
		if (a[i] >= z[m].second) { break; }
		sum += z[m].second;
		if (z[m].first == 1) {
			if (m-- == 0) {
				++i;
				break;
			}
			continue;
		}
		z[m].first -= 1;
	}
	for (;i < N; ++i) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
int m1,m2,d1,d2;
int main(){
  cin >> m1 >> d1 >> m2 >> d2;
  cout << (m1 != m2 && d2 == 1 ?1:0) << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  ll n=0;
  cin>>n;
  map<ll,ll>factor;
  for(ll i=2;i*i<=n;++i){
    while(n%i==0){
      ++factor[i];
      n/=i;
    }
  }
  if(n!=1) ++factor[n];
  ll ans=0;
  for(auto i:factor){
    for(ll j=1;j<=i.S;++j){
      i.S-=j;
      ++ans;
    }
  }
  cout<<ans;  
}

Measured memory_bytes: 3668
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,k = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	z = zeros(Int,n)
	for i in 1:n
		z[a[i]] += 1
	end
	z = sort(z)
	x = 0
	for i in n-k+1:n
		x+=z[i]
	end
	println(n-x)
end

main()

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

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

    int f = 0;
    if (a == 5) f++;
    if (b == 5) f++;
    if (c == 5) f++;

    if (f == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

uint64_t solve(int32_t n, const int32_t* a) {
	int32_t i;
	uint64_t cost = 0;
	int64_t value = 0;
	int64_t target = 1;
	for (i = 0; i < n; i++) {
		value += a[i];
		if (value == 0 || (value > 0) != (target > 0)) {
			int64_t diff = value - target;
			if (diff < 0) diff = -diff;
			cost += diff;
			value = target;
		}
		target = -target;
	}
	return cost;
}

int main(void) {
	int32_t n;
	int32_t* a;
	int32_t i;
	uint64_t c1, c2;
	if (scanf("%" SCNd32, &n) != 1) return 1;
	a = malloc(sizeof(*a) * n);
	if (a == NULL) return 2;
	for (i = 0; i < n; i++) {
		if (scanf("%" PRId32, &a[i]) != 1) return 1;
	}
	c1 = solve(n, a);
	for (i = 0; i < n; i++) a[i] = -a[i];
	c2 = solve(n, a);
	printf("%" PRIu64 "\n", c1 <= c2 ? c1 : c2);
	free(a);
	return 0;
}


Measured memory_bytes: 512
N, M = map(int, input().split())

AC = [False] * (N + 1)
WA = [0] * (N + 1)
for _ in range(M):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        AC[p] = True
    if s == "WA" and not AC[p]:
        WA[p] += 1

cnt = 0
for a, w in zip(AC, WA):
    if a:
        cnt += w

print(sum(AC), cnt)


Measured memory_bytes: 4596
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a=n/4;
  int b=0;
  while(4*a+7*b!=n)
  {
    if(a>0)--a;
    if(4*a+7*b<n)b++;
    if(a<=0)break;
  }
  if(4*a+7*b==n){cout<<"Yes\n";}
  else{cout<<"No\n";}
  return 0;
  
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(),(x).end()

int main() {
	string s;
	cin >> s;

	int ans = 0;

	rep(i, s.size() - 1){
		if(s[i] == s[i + 1]){
			if(s[i] == '0'){
				s[i + 1] = '1';
			}else{
				s[i + 1] = '0';
			}
			ans ++;
		}
	}

	cout << ans << endl;


    return 0;
}



Measured memory_bytes: 512
H,W = map(int,input().split())
S = [(W+2)*"."]+["."+input()+"." for h in range(H)]+[(W+2)*"."]
ans = "Yes"

for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w]=="#" and S[h][w-1]==S[h][w+1]==S[h-1][w]==S[h+1][w]==".":
      ans = "No"

print(ans)

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

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A == B && A != C) {
    cout << "Yes" << endl;
  } else if(B == C && A != B) {
    cout << "Yes" << endl;
  } else if(A == C && A != B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<stdint.h>
#include<limits.h>

#include<iomanip>
#include<cmath>
using namespace std;



int main() {
	priority_queue<int> q;
	int n, m,x;
	cin >> n >> m;
	for (int i = 0;i < n;i++) {
		cin >> x;
		q.push(x);
	}

	for (int i = 0;i < m;i++) {
		int val = q.top();
		q.pop();
		val = val / 2;
		q.push(val);
	}
	long long tot = 0;
	while (!q.empty()) {
		tot += q.top();
		q.pop();

}
	cout << tot;
	return 0;
}

Measured memory_bytes: 892
S=input()
X=[]
SS=""
cnt=0
for s in S:
    if s=="x":
        cnt+=1
    else:
        SS+=s
        X.append(cnt)
        cnt=0
X.append(cnt)
flag=True
for i in range(len(SS)//2):
    if SS[i]!=SS[-i-1]:
        flag=False
        break
ans=0
for i in range(len(X)//2):
    ans+=abs(X[i]-X[-i-1])
if flag:
    print(ans)
else:
    print(-1)

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

ll comb(ll n,ll r)
{
    if (n==1) return 1;
    if (r == 0 || r == n) return (1);
    else if (r == 1) return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

int main()
{
    ll N;
    cin >> N;
    map<string,ll> dic;
    for(int i=0;i<N;i++)
    {
        string s;cin>>s;
        sort(s.begin(),s.end());
        dic[s]++;
    }
    ll res=0;
    for(auto it=dic.begin();it!=dic.end();it++)
    {
        ll count=it->second;
        if(1<count)res+=comb(count,2);
    }
    cout<<res; 
    return 0;
}

Measured memory_bytes: 11336
#include <bits/stdc++.h>
    using namespace std;
    int main(int argc, char const *argv[])
    {
    	int n;
    	cin>>n;
    	vector <string> s1(n), s2(n);
    	for (int i = 0; i < n; ++i)
    	{
    		cin>>s1[i];
    	}
    	int ans = 0;
    	for (int i = 0; i < n; ++i)
    	{
    		for (int j = 0; j < n; ++j)
    		{
    			s2[j] = s1[j].substr(i) + s1[j].substr(0, i);
    		}
    		bool ok = true;
    		for (int j = 0; j < n; ++j)
    		{
    			for (int k = 0; k < n; ++k)
    			{
    				if(s2[j][k] != s2[k][j])
    					ok = false;
    			}
    		}
    		if(ok)
    			ans+=n;
    	}
    	cout<<ans<<"\n";
    	return 0;
    }

Measured memory_bytes: 640
A,B,C,X,Y = map(int,input().split(" "))
P = 0
ans = 0
finans = 10 ** 9
for i in range(0,max(X,Y) * 2 + 1,2):
    ans = 0
    ans += C * i
    if X - i // 2 > 0:
        ans += A * (X - i // 2)
    if Y - i // 2 > 0:
        ans += B * (Y - i // 2)
    if ans < finans:
        finans = ans
print(finans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int a, b, c;
	for(a=1;a<10;a++){
	 for(b=1;b<10;b++){
	  c=a*b;
	 printf("%dx%d=%d\n", a, b, c);
	 }
	}
	return 0;
}

Measured memory_bytes: 524
n,m,q=map(int,input().split())
query=[]
for _ in range(q): query.append(list(map(int,input().split())))
ans=0
def rec(a):
    if len(a)==n+1:
        temp=0
        for qu in query:
            if a[qu[1]]-a[qu[0]]==qu[2]: temp+=qu[3]
        global ans
        ans=max(ans,temp)
        return
    for i in range(a[-1],m+1):
        cp=a[:]
        cp.append(i)
        rec(cp)
rec([1])
print(ans)

Measured memory_bytes: 9216