akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main() {
    while (true) {
        int H;
        cin >> H;
        if (H == 0) break;
        vector<vector<int>> P(H, vector<int>(5));
        for (int i = 0; i < H; ++i) cin >> P[i][0] >> P[i][1] >> P[i][2] >> P[i][3] >> P[i][4];
        
        int score = 0;
        while (true) {
            // 消えるかどうか判定
            vector<vector<bool>> D(H, vector<bool>(5));
            bool judge = false;
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < 3; ++j) {
                    if (P[i][j] == P[i][j + 1] && P[i][j + 1] == P[i][j + 2] && P[i][j] != 0) {
                        judge = true;
                        D[i][j] = true;
                        D[i][j + 1] = true;
                        D[i][j + 2] = true;
                    }
                }
            }
            if (!judge) break;
            
            // 消す
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < 5; ++j) {
                    if (D[i][j]) {
                        score += P[i][j];
                        P[i][j] = 0;
                    }
                }
            }
            
            // 落とす
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < H - 1; ++j) {
                    for (int k = 0; k < 5; ++k) {
                        if (P[j + 1][k] == 0) {
                            P[j + 1][k] = P[j][k];
                            P[j][k] = 0;
                        }
                    }
                }
            }
        }
        
        cout << score << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt(), q = scanner.nextInt();
			// 町と町の間の移動最短距離
			int[][] d = new int[n][n];
			IntStream.range(0, n).forEach(i -> {
				Arrays.fill(d[i], Integer.MAX_VALUE >> 1);
				d[i][i] = 0;
			});
			int[] r = new int[q];
			IntStream.range(0, q).forEach(i -> r[i] = scanner.nextInt() - 1);
			IntStream.range(0, m).forEach(i -> {
				int a = scanner.nextInt() - 1;
				int b = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				d[a][b] = d[b][a] = c;
			});
			warshallFloyd(d, n);
			System.out.println(getResult(d, r, -1, new boolean[q], 1));
		}
	}

	/**
	 * 町と町の間の移動最短距離をワーシャル–フロイド法で計算する
	 * 
	 * @param d 町と町の間の移動最短距離の配列
	 * @param n 町の数
	 */
	private static void warshallFloyd(int[][] d, int n) {
		IntStream.range(0, n).forEach(k -> IntStream.range(0, n)
				.forEach(j -> IntStream.range(0, n).forEach(i -> d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]))));
	}

	/**
	 * 解説通りに実装したメソッド
	 * 
	 * @param d       町と町の最短距離の配列
	 * @param r       訪ねる町の配列
	 * @param prev    直前に訪ねた町（存在しないときは-1）
	 * @param visited 町が訪ねたかどうかの配列
	 * @param depth   訪ねた町の数
	 * @return 訪ねる町をすべて訪ねたときの移動距離
	 */
	private static int getResult(final int[][] d, final int[] r, int prev, boolean[] visited, int depth) {
		if (depth > r.length) {
			return 0;
		}
		int result = Integer.MAX_VALUE >> 1;
		for (int i = 0; i < r.length; i++) {
			if (!visited[i]) {
				visited[i] = true;
				if (-1 == prev) {
					result = Math.min(result, getResult(d, r, i, visited, depth + 1));
				} else {
					result = Math.min(result, getResult(d, r, i, visited, depth + 1) + d[r[prev]][r[i]]);
				}
				visited[i] = false;
			}
		}
		return result;
	}
}


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

int main(){
    int n, k, x, l[100];
    cin >> n>>k;
    for (int i = 0; i < n;i++){
        cin >> l[i];
    }
    
    sort(l, l + n, greater<int>());
    x = 0;
    for (int i = 0; i < k;i++){
        x += l[i];
    }
    cout << x << endl;
}

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


#define NUM 55

struct Point{
	int x,y;
};

int N,K;
Point points[NUM];

int main(){

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

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

		scanf("%d %d",&points[i].x,&points[i].y);
	}

	ll ans = LLONG_MAX;
	ll L,R,U,D;

	int count;

	for(int a = 0; a < N; a++){
		for(int b = 0; b < N; b++){
			for(int c = 0; c < N; c++){
				for(int d = 0; d < N; d++){
					L = min(points[a].x,points[b].x);
					R = max(points[a].x,points[b].x);
					U = max(points[c].y,points[d].y);
					D = min(points[c].y,points[d].y);

					if((R-L)*(U-D) >= ans)continue;

					count = 0;
					for(int i = 0; i < N; i++){
						if(points[i].x >= L && points[i].x <= R && points[i].y >= D && points[i].y <= U)count++;
					}

					if(count >= K){
						ans = min(ans,(R-L)*(U-D));
					}
				}
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <vector>
using namespace std;

const int MAX_N = 1000;
const int INF = 1<<29;

int N, M;
int as[MAX_N];

int solve(){
	int mini = INF, key = INF, ans = -1;
	bool hope = false;
	for(int i=0; i<N; i++){
		vector<int> ts;ts.reserve(M+1);
		for(int j=0; j<=M; j+=as[i]){
			ts.push_back(j);
		}
		vector<int> escp; escp.reserve(ts.size());
		for(int j=0, T = ts.size(); j<T; j++){
			int tme = ts[j];
			if( tme > mini || (tme == mini && as[i] >= key) ){
				escp.push_back(tme);
			}
		}
		if(!escp.empty()){
			int tme = escp[0];
			if(tme == mini && as[i] == key){
				hope = true;
			}
		}
		else{
			hope = false;
			mini = ts.back();
			key = as[i];
			ans = i;
		}
	}
	return hope ? N : ans + 1;
}

int main(){

	while(scanf("%d%d",&N, &M), N){
		for(int i=0; i<N; i++){
			scanf("%d", as+i);
		}
		printf("%d\n", solve());
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}
int main(){
  int w,h,x,y,ans =0;
  cin >> w >>h >>x >>y;
  if(2*x ==w && 2*y==h){
    ans =1 ;
  }
  double  S= w*h;
  cout << (double)w*(double)h /2  <<" "<< ans <<endl;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
s, c = m.times.map { gets.split.map(&:to_i) }.transpose

ans = Array.new(n, 0)

m.times do |i|
  if n >= 2 && s[i] == 1 && c[i] == 0
    puts -1
    exit 0
  elsif ans[s[i] - 1] != 0 && ans[s[i] - 1] != c[i]
    puts -1
    exit 0
  else
    ans[s[i] - 1] = c[i]
  end
end

ans[0] = 1 if n >= 2 && ans[0] == 0
puts ans.join


Measured memory_bytes: 3836
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, d[50], ans = 0;
   cin >> n;
   FOR(i, 0, n)
   cin >> d[i];
   FOR(i, 0, n)
   {
      FOR(j, i + 1, n)
      ans += d[i] * d[j];
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    
    cin >> A[i];
  }
  int ans = 0;
  bool ts = false, ts1 = true;
  while(ts1){
    ts = false;
    ts1 = false;
    for(int i=0;i<N;i++){
      if(!ts){
        if(A[i] > 0){
          ts = true;
          ans++;
          ts1 = true;
        }
        else{
          continue;
        }
      }
      if(ts){
        if(A[i] <= 0){
          ts = false;
        }
        else{
          A[i]--;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
main(){
  
  int kosu,array[100],key;
  int i,j,k;
  
  scanf("%d",&kosu);
  
  for(i = 0 ; i < kosu ; i++){
    scanf("%d",&array[i]);
  }


  for(k = 0 ; k < kosu ; k++){
	printf("%d",array[k]);
	if(k < kosu - 1) printf(" ");
      }
      printf("\n");


  for(i = 1 ; i < kosu ; i++){

    key = array[i];

    j = i - 1;


    
    while((j >= 0) && (array[j] > key)){
      
      array[j + 1] = array[j];
      j--;
      
    }
    
    array[j + 1] = key;

         
      for(k = 0 ; k < kosu ; k++){
	printf("%d",array[k]);
	if(k < kosu - 1) printf(" ");
      }
      printf("\n");



  }
  
  
  return 0;

}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10010,p=998244353;
int inc(int x,int y){x+=y;return x>=p?x-p:x;}
int mul(int x,int y){return (ll)x*y%p;}
int power(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=mul(x,x))
		if (y&1) ans=mul(ans,x);
	return ans;
}
int dp[N][N],fac[N],ifac[N],n,m,len;
char s[N],t[N];
int C(int n,int m){
	return mul(fac[n],mul(ifac[m],ifac[n-m]));
}
int main()
{
	scanf("%s%s",s,t);
	len=strlen(s);
	for (int i=0;i<len;i++)
	if (s[i]=='1') t[i]=='1'?n++:m++;
	dp[0][0]=1;
	for (int i=0;i<=n;i++)
	for (int j=0;j<=m;j++){
		if (j) dp[i][j]=inc(dp[i][j],mul(dp[i][j-1],j*j));
		if (i&&j) dp[i][j]=inc(dp[i][j],mul(dp[i-1][j],i*j));
	}
	fac[0]=1;
	for (int i=1;i<N;i++) fac[i]=mul(fac[i-1],i);
	ifac[N-1]=power(fac[N-1],p-2);
	for (int i=N-1;i;i--) ifac[i-1]=mul(ifac[i],i);
	int ans=0;
	for (int i=0;i<=n;i++) ans=inc(ans,mul(mul(fac[i],fac[i]),mul(dp[n-i][m],mul(C(n+m,i),C(n,i)))));	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 389632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;

typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//Ordered set
//pbds s1

ll n, x, m;

ll MOD (ll a, ll val) {
    if (a < 0)
        a += val;
    return (a % val);
}

void testCase() {
    cin >> n >> x >> m;
    map <ll, int> track;
    list<ll> store;
    ll ans = x;
    n--;
    ll prev = x;
    track[x] = 1;
    store.push_back (x);
    while (n) {
        prev = MOD(prev*prev, m);
        if (track[prev]) {
            //it is a loop
            break;
        }
        else {
            track[prev] = 1;
            store.push_back (prev);
            ans += prev;
            n--;
        }
    }
    if (n) {
        //find prev;
        while (store.front() != prev) {
            store.pop_front();
        }
        ll cnt = ll (store.size());
        ll sum = 0;
        for (ll v : store)
            sum += v;
        ll take = n / cnt;
        ans = ans + (take)*sum;
        n = n - take*cnt;
        while (n--) {
            ans += store.front();
            store.pop_front();
        }
    }
    cout << ans << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  multiset<int> st;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    st.insert(x);
  }
  int res = 0;
  while (!st.empty()) {
    int x = *st.rbegin();
    st.erase(--st.end());
    int y = 1; while (y < x) y += y;
    int z = (__builtin_popcount(x) == 1 ? x : y - x);
    if (st.count(z)) {
      st.erase(st.find(z));
      ++res;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 13040
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(){
	int h;
	int n;
	int *a = NULL;
	int i;
	
	scanf("%d %d", &h, &n);
	
	a = (int *)malloc(sizeof(int)*n);
	
	for(i=0; i<n; ++i){
		scanf("%d", &a[i]);
		h-=a[i];
		if(h<=0){
			printf("Yes");
			break;
		}
		if(i==n-1){
			printf("No");
		}
	}
	
	free(a);
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <utility>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;
int main() {
	int n;
	cin >> n;
	cout << n * 800 - 200 * (n / 15);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	fast_io();
	int n,m;
	cin >> n >> m;
	vector<int> div;
	fu(i,1,sqrt(m)+3){
		if(m % i == 0){div.pb(i);div.pb(m/i);}
	}
	int ans = 0;
	for(int d:div){
		ll mx = 1LL * n * d;	
		if(mx <= m)ans = max(ans, d);	
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mo 998244353
void fwxo(int *a,int l,int r){
	if(l==r)return;
	int md=(l+r)/2;
	fwxo(a,l,md);fwxo(a,md+1,r);
	for(int i=l;i<=md;i++){
		int c=a[i],d=a[md+i-l+1];
		a[md+i-l+1]=(c-d+mo)%mo;
		a[i]=(c+d)%mo;
	}
}
int qp(int x,int y){
	int r=1;
	for(;y;y>>=1,x=x*x%mo)
		if(y&1)r=r*x%mo;
	return r;
}
int n,a[10000010],s,f[10000010];
signed main(){
	cin>>n;
	for(int i=0;i<(1<<n);i++){
		cin>>a[i];
		s=(s+a[i])%mo;
	}
	for(int i=0;i<(1<<n);i++)
		a[i]=a[i]*qp(s,mo-2)%mo;
	fwxo(a,0,(1<<n)-1);
	s=0;
	for(int i=1;i<(1<<n);i++){
		f[i]=qp(a[i]-1,mo-2);
		s=(s+f[i])%mo;
	}
	f[0]=(-s+mo)%mo;
	fwxo(f,0,(1<<n)-1);
	for(int i=0;i<(1<<n);i++)
		cout<<f[i]<<'\n';
}

Measured memory_bytes: 7652
#include <stdio.h>

int main(){
	char s[5];
	int i, j, cnt;

	scanf("%s", s);

	for(i=0; i<4; i++){
		cnt=0;
		for(j=0; j<4; j++){
			if(s[i] == s[j])
				cnt++;
		}

		if(cnt != 2){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");

	return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	char word[n][11];
	for(int i=0; i<n; i++){
		scanf("%s", &word[i]);
	}
	
	int final;
	int i=1;
	while(1){
		if(i==n){
			printf("Yes");
			return 0;
		}
		final= strlen(word[i-1])-1;
		//printf("first:%c, final:%c", word[i][0], word[i-1][final]);
		if(word[i][0] != word[i-1][final]){
			printf("No");
			return 0;
		}
		for(int j=0; j<i; j++){
			if(strcmp(word[i], word[j]) == 0){
				printf("No");
				return 0;
			}
		}
		
		i++;
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll ;
const int MAX=3e5+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;

int a[MAX];
void solve(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans=0;
    ll maxx=a[0];
    for(int i=1;i<n;i++){
        if(a[i]<maxx){
            ans+=maxx-a[i];
        }else{
            maxx=a[i];
        }
    }
    cout<<ans;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 5160
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int N;

int main() {
	cin >> N;
	for (int i = 111; i <= 999; i += 111)
	{
		if (N <= i) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    cout << a.back() - a.front() << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const long long MAXN=2005,INF=0x7f7f7f7f7f7f7f7fll;
long long n,x;
long long d[MAXN][MAXN];
int main()
{
	//freopen("slime.in","r",stdin);
	//freopen("slime.out","w",stdout);
	scanf("%lld%lld",&n,&x);
	for(long long i=1;i<=n;i++)
		scanf("%lld",&d[i][0]);
	for(long long i=1;i<=n;i++)
	{
		for(long long j=1;j<n;j++)
		{
			d[i][j]=min(d[i][j-1],d[((i-j-1)+n)%n+1][0]);
		}
	}
	long long ans=INF;
	for(long long i=0;i<n;i++)
	{
		long long jans=i*x;
		for(long long j=1;j<=n;j++)
		{
			jans+=d[j][i];
		}
		ans=min(jans,ans);
	}
	printf("%lld\n",ans);
	fclose(stdin);
	fclose(stdout);
}

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

int main()
{
  int A, B;
  cin >> A >> B;
  
  int ans = -1;
  if (A >= 1 && A <= 9)
  {
    if (B >= 1 && B <= 9)
    {
      ans = A * B;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# 解説AC
MOD = 10**9 + 7


def main():
    S = [s for s in input()[::-1]]
    N = len(S)
    dp = [[0]*13 for i in range(N+1)]
    dp[0][0] = 1
    d = 1
    for i in range(N):
        for j in range(13):
            if S[i] != "?":
                a = int(S[i])
                ne = ((a*d)+j) % 13
                dp[i+1][ne] += dp[i][j]
                dp[i+1][ne] %= MOD
            else:
                for k in range(10):
                    ne = ((k*d)+j) % 13
                    dp[i+1][ne] += dp[i][j]
                    dp[i+1][ne] %= MOD
        d *= 10
        d %= 13
    print(dp[N][5] % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65952
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int k, n;
  cin >> k >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  int temp = k - (v[0] + (k - v[n-1]));
  rep(i,n-1) {
    temp = min(temp, k - (v[i+1] - v[i]));
  }
  cout << temp << endl;
}

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

Measured memory_bytes: 4000
A,B,C,X,Y = map(int,input().split())

ans = A*X+B*Y
price = 0
AB = 2*C

for i in range(max(X,Y)+1):
    price = AB*i + max(0,X-i)*A + max(0,Y-i)*B
    ans = min(ans,price)

print(ans)

Measured memory_bytes: 65432
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long n = sc.nextLong();
		long m = sc.nextLong();
		
		// 計算
		long result = 0;
		if(n*2 > m){
		    result = m/2;
		}else{
		    result = n + (m-2*n)/4;
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 21204
from collections import Counter
def check():
    H, W = map(int, input().split())
    S = ''
    for i in range(H):
        S += input()
    C = Counter(S)
    vmod4 = list(map(lambda x:x%4,C.values()))
    V = Counter(vmod4)
    two = (H%2)*(W//2)+(H//2)*(W%2)
    odd = (H%2)*(W%2)
    if V[2]<= two and V[1]+V[3]<=odd:
        return True
    return False
if check():
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, k);
	pi a[n + 1];
	FOR (i, 1, n) cin >> a[i].se >> a[i].fi;
	sort(a + 1, a + n + 1);
	
	set <int> s;
	int sum = 0, ans = 0, first[n + 1] = {};
	FORD (i, n, n - k + 1)
	{
	    if (!s.count(a[i].se))
	    {
	        s.insert(a[i].se);
	        first[i] = 1;
	    }
	    sum += a[i].fi;
	}
	
	ans = sum + sz(s)*sz(s);
	
	int cnt = n - k + 1;
	FORD (i, n - k, 1)
	{
	    if (!s.count(a[i].se))
	    {
	        s.insert(a[i].se);
	        sum += a[i].fi;
	        while (first[cnt])
	        {
	            cnt++;
	            if (cnt > n) {cout << ans; return 0;}
	        }
	        
	        sum -= a[cnt].fi;
	        ans = max(ans, sum + sz(s)*sz(s));
	        cnt++;
	        if (cnt > n) {cout << ans; return 0;}
	    }
	}
	
	cout << ans;
}



















Measured memory_bytes: 8920
s = str(input())

dream = 'dream'
dreamer = 'dreamer'
erase = 'erase'
eraser = 'eraser'

while s !='':
  if s.endswith(dream):
    s = s[:-5]
  elif s.endswith(dreamer):
    s = s[:-7]
  elif s.endswith(erase):
    s = s[:-5]
  elif s.endswith(eraser):
    s = s[:-6]
  else:
    print('NO')
    exit()
 
print('YES')

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
    string s;
    cin>>s;
    int n=s.size();
    s = s + "R";

    vector<int> r(n);

    int mode = 'R';
    int t=1;

    FOR(i,1,n+1){
        if(mode == 'R'){
            t++;
            if(s[i] == 'L'){
                mode = 'L';
                r[i-1] += t/2;
                r[i] += (t+1)/2;
                t=0;
            }
        }
        else {
            if(s[i] == 'R'){
                mode = 'R';
                r[i-t-2] += (t+1)/2;
                r[i-t-1] += (t)/2;
                t=0;
            }
            t++;
        }
    }

    REP(i,n){
        if(i!=0){
            cout<<" ";
        }
        cout<<r[i];
    }
    cout<<endl;
    return;
	
}

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

Measured memory_bytes: 1004
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

Measured memory_bytes: 256
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxn 270000
#define maxm 1000006
#define maxc 1000000007
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
const int mod = maxc;
int Mul(int a,int b) {return 1ll*a*b%mod;}
int Add(int a,int b) {a += b;if (a >= mod) a -= mod;return a;}
int n,a[maxn],ans,sum[maxn];
vector <int> de;
void Dfs2(int u,int cur,bool left)
{
    if (u == 1) return;
    cur = Mul(cur,u);
    if (left)
    {
        sum[u] = Add(sum[u],cur);
    }
    else
    {
        ans = Add(ans,Mul(u >> 1,Mul(sum[u ^ 1],cur)));
    }
    Dfs2(u >> 1,cur,left);
}
void Dfs1(int u,int cur,bool left)
{
    cur = Mul(cur,u);
    if (u >= n)
    {
        int v = a[u];
        Dfs2(v,cur,left);
        de.pb(v);
        return;
    }
    Dfs1(2*u,cur,left);
    Dfs1(2*u+1,cur,left);
}
int main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie();
    if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    read(n);
    //cin >> n;
    n = 1 << (n-1);
    FOR(i,1,n)
    {
        //cin >> a[i + n - 1];
        read(a[i+n-1]);
        a[i + n - 1] += n - 1;
    }
    FOR(i,1,n - 1)
    {
        Dfs1(2*i,i,1);
        Dfs1(2*i+1,1,0);
        for (int &u : de)
        {
            while (u)
            {
                sum[u] = 0;
                u >>= 1;
            }
        }
        de.clear();
    }
    write(ans);
    //cout << ans;
    return 0;
}


Measured memory_bytes: 5312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String rud = "RUD";
		String lud = "LUD";
		
		String s = sc.next();
		
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if (i % 2 == 1) {
				if (c == 'R') {
					System.out.println("No");
					return ;
				} 
			} else {
				if (c == 'L') {
					System.out.println("No");
					return ;
				} 
			}
		}
		System.out.println("Yes");
		
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 21844
n = int(input())
h = [int(hi) for hi in input().split()]

inf = float('inf')

dp = [inf] * n

dp[0] = 0

for i in range(0, n-1):
  dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
  if i < n-2:
    dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]))

print(dp[-1])

Measured memory_bytes: 13980
#include<iostream>
#include<vector>
#include<cmath>

/*
int main(){

	int N;
	unsigned long int ans = 0;
	std::cin >> N;

	std::vector<unsigned long int> list(N,0);

	std::vector<unsigned long int> sum(N,0);

	for (int i = 0; i < N;i++){
		std::cin >> list[i];
		if(!i){
			continue;
		}
		for (int j = 0; j <i;j++){
			sum[j] += list[i];
		}
	}


	for (int i = 0; i < N-1; i++){
		ans += (list[i] * sum[i])%1000000007;
	}
	ans %= 1000000007;

	std::cout << ans << std::endl;
}
*/

int main(){
	int N, K;
	std::cin >> N >> K;

	std::vector<int> list(N, 0);

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

	int num = 0;

	for (num = 0; list[num] != 1;num++){
	}

	std::cout << (int)ceil((list.size()-1)*1.0/(K-1)) << std::endl;
}

Measured memory_bytes: 3768
S = input()


def kai(text):
    if text == text[::-1]:
        return True
    else:
        return False


if kai(S) and kai(S[0:int((len(S) - 1) / 2)]) and kai(S[int((len(S) + 3) / 2)-1:len(S)]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <iostream>

int main()
{
  int TakahashiAP = 0;
  int TakahashiHP = 0;
  int AokiAP = 0;
  int AokiHP = 0;

  std::cin >> TakahashiHP >> TakahashiAP >> AokiHP >> AokiAP;

  while (true)
  {
    AokiHP -= TakahashiAP;
    if (AokiHP <= 0)
    {
      std::cout << u8"Yes" << std::endl;
      break;
    }

    TakahashiHP -= AokiAP;
    if (TakahashiHP <= 0)
    {
      std::cout << u8"No" << std::endl;
      break;
    }
  }
  return 0;
}

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

int main() {
	string s;
	cin >> s;
	for (int i = 1;i <= s.size();i++) {
		if (i % 2 == 1) {
			if (s[i-1] == 'L') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (s[i-1] == 'R') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
x,y = map(int,input().split())
ans = 1000000000000000000000000000000
apple = 0
for i in range(1, x+1):
    apple += i+y-1
    ans = min(ans, abs(i+y-1))
#print(ans, apple)

if abs(apple-ans) <= abs(apple+ans):
    print(apple-ans)
else:
    print(apple+ans)

Measured memory_bytes: 38384
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
s=input()
ans=n
for i in range(1,n):
    if s[i]==s[i-1]:
        ans-=1
print(ans)

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

class Program
{
    static void Main(string[] args)
    {
        var A = sc.ReadDouble();
        var B = sc.ReadDouble();
        var X = sc.ReadDouble();
        var S = X / A;

        if (S * 2.0 > A * B)
        {
            // 半分より多い
            var h = X / (A * A);
            var h2 = B - h;
            var ans = ToAngle(Math.Atan2(2 * h2, A));
            Console.WriteLine(ans);
        }
        else
        {
            // 半分以下
            var s = X / A;
            var h = s / B * 2;
            var ans = 90 - ToAngle(Math.Atan2(h, B));
            Console.WriteLine(ans);
        }
    }

    static double ToAngle(double radian)
    {
        return radian * 180 / Math.PI;
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}



Measured memory_bytes: 13140
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, less<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(int i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(int i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(int i=0;i<int(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(int)(b);++i)
#define rrep(i,n) for(int i=int(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define irep(i,n) for(int i=int(n);;++i)
#define all(n) begin(n),end(n)
inline auto gcd(auto A,auto B){return B?gcd(B,A%B):A;}
inline auto lcm(auto A,auto B){return A/gcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={-1,1,0,0,1,1,-1,-1};
const vector<lint> dy={0,0,-1,1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

int main(){
    lint n;
    cin>>n;
    string s;
    cin>>s;
    lint ans=0;
    rep(i,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            ans++;
        }
    }
    cout<<ans<<endl;
}


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

#define MAX 500001

void merge(int *,int,int,int);
void mergeSort(int *,int,int);
 
int count=0; 
 
int main(){
  int n,i;
  int S[MAX];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
    if(S[i]<0 || S[i]>1000000000){
      exit(1);
    }
  }
 
  mergeSort(S,0,n);
 
  for(i=0;i<n-1;i++){
    printf("%d ",S[i]);
  }
  printf("%d\n",S[n-1]);
  printf("%d\n",count);
 
  return 0;
}


void merge(int *A,int l,int m,int r){
  int n1=m-l;
  int n2=r-m;
  int i,j,k;
  int *L,*R;
 
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
 
  for(i=0;i<=n1-1;i++){
    L[i]=A[l+i];
  }
 
  for(j=0;j<=n2-1;j++){
    R[j]=A[m+j];
  }
 
  L[n1]=1000000000;
  R[n2]=1000000000;
 
  i=0;
  j=0;
 
  for(k=l;k<=r-1;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }else{
      A[k]=R[j];
      j=j+1;
    }
 
    count++;
  }
 
  free(L);
  free(R);
}

void mergeSort(int *A,int left,int right){
  int mid;
 
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
bool isBlack(vector<vector<char>> &canbas, int hi, int wi) {
  if(canbas[hi][wi+1] == '#') return true;
  if(canbas[hi][wi-1] == '#') return true;
  if(canbas[hi+1][wi] == '#') return true;
  if(canbas[hi-1][wi] == '#') return true;
  return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int height, width;
  cin >> height >> width;
  vector<vector<char>> canbas(60, vector<char>(60, '.'));
  rep(hi, height) {
    string str;
    cin >> str;
    rep(wi, width) {
      canbas[hi+1][wi+1] = str[wi];
    }
  }

  rep(hi, height) {
    rep(wi, width) {
      if(canbas[hi][wi] == '.') continue;
      if(isBlack(canbas, hi, wi) == false) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

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

}

Measured memory_bytes: 256
n,m,c = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
ans = 0
n.times do
    a = gets.split.map(&:to_i)
    r = c
    m.times do |i|
        r += a[i]*b[i]
    end
    ans += 1 if r > 0
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll dp[220][220];

int main(){cout<<fixed<<setprecision(10);
		   //ワーシャルフロイド法O(n^3)
           //順列全探索
           int n,m,r;
           cin>>n>>m>>r;
           vin city(r);
           rep(i,0,r){
             cin>>city[i];
            city[i]--; 
           }
           rep(i,0,220)rep(j,0,220){
             if(i!=j)dp[i][j]=INF;
           }
           ll a,b,c;
           rep(i,0,m){
             cin>>a>>b>>c;
             a--;b--;
             chmin(dp[a][b],c);
             chmin(dp[b][a],c);
           }
           rep(k,0,n){//途中点
            rep(j,0,n){
             rep(i,0,n){
              chmin(dp[i][j],dp[i][k]+dp[k][j]); 
             }
            }
           }
           
           ///////////////////
           vll order(r);
           rep(i,0,r) order[i]=i;
           ll ans=INF;
           do{
             ll cnt=0;
            rep(i,1,r){
              ll from=city[order[i-1]],to=city[order[i]];
             cnt+=dp[from][to];
            }
             chmin(ans,cnt);
           }while(next_permutation(order.begin(),order.end()));
           cout<<ans<<endl;
}




Measured memory_bytes: 3976
while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    a = [int(input()) for i in range(n)]
    c = 0
    for i in range(k):
        c += a[i]
        b = c
    for i in range(k, n):
        c += a[i]
        c -= a[i - k]
        b = max(b,c)
    print(b)


Measured memory_bytes: 9624
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    vector<int>a(2);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x%2==0){
            a.at(0)++;
        }
        else{
            a.at(1)++;
        }
    }
    if(a.at(1)%2==0){
        a.at(0)++;
        a.at(1)=0;
    }
    else{
        a.at(0)++;
        a.at(1)=1;
    }
    // cout<<a.at(0)<<" "<<a.at(1)<<endl;
    if(a.at(0)!=0){
        a.at(0)=1;
    }
    if((a.at(0)+a.at(1))%2==0){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }




    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main {

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

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());

		ArrayList<ArrayList<Integer>> list = new ArrayList<>();

		for (int i = 0; i <= 100001; i++) {
			list.add(new ArrayList<>());
		}

		for (int i = 0; i < n; i++) {
			str = br.readLine().split(" ");

			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);

			list.get(a).add(b);
		}

		long sum = 0;
		for (int i = 0; i <= m; i++) {
			for (int j = 0; j < list.get(i).size(); j++) {
				pq.add(list.get(i).get(j));
			}
			if (pq.isEmpty())
				continue;
			sum += pq.poll();
		}

		System.out.println(sum);
	}

}

Measured memory_bytes: 65260
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       s:Chars,
       t:Chars,
    }

    let mut ans: usize = INF_USIZE;
    for i in 0..s.len() {
        if i + t.len() > s.len() {
            break;
        }

        let mut c = 0;
        for j in 0..t.len() {
            if t[j] != s[i + j] {
                c += 1;
            }
        }
        mydbg!(c);
        ans = min(ans, c);
    }

    echo!(ans);
}


Measured memory_bytes: 2052
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()
nums = [0]*10**6
for i in range(n):
  nums[a[i]]+=1
q=ni()
ans=0
for i in range(len(nums)):
  ans+=nums[i]*i

for i in range(q):
  b,c=nm()
  ans-=nums[b]*b
  ans+=nums[b]*c
  nums[c]+=nums[b]
  nums[b]=0
  print(ans)


Measured memory_bytes: 23096