akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  long long sum = 0;
  for (int i = 0; i < N; i++){
    sum += A[i];
  }
  long long C = N * (N + 1) / 2;
  if (sum % C != 0){
    cout << "NO" << endl;
  } else {
    long long cnt = sum / C;
    vector<long long> D(N);
    for (int i = 0; i < N - 1; i++){
      D[i] = A[i + 1] - A[i];
    }
    D[N - 1] = A[0] - A[N - 1];
    for (int i = 0; i < N; i++){
      D[i] -= cnt;
    }
    bool ok = true;
    /*
    for (int i = 0; i < N; i++){
      cout << D[i] << ' ';
    }
    cout << endl;
    */
    for (int i  = 0; i < N - 1; i++){
      if (D[i] % N != 0 || D[i] > 0){
        ok = false;
      }
    }
    if (ok){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i,n) for (ll i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = 0;	//青の数

	if (a == 0) {
		cout << ans << endl;
		return 0;
	}

	//while (1) {	//操作

	//	p += a;
	//	ans += a;
	//	if (p >= n) {
	//		ans -= p - n;
	//		cout << ans << endl;
	//		return 0;
	//	}

	//	p += b;
	//	if (p >= n) {
	//		cout << ans << endl;
	//		return 0;
	//	}

	//}

	//1回の操作でa+bだけ列が増える
	//nを超えるための操作数は？

	ll c = n / (a + b);
	if (n % (a + b) != 0) c++;

	//超えた時の列の数は
	ll p = c * (a + b);

	//nよりいくつ大きいか
	ll d = p - n;

	//超えた数が赤（b）より大きければ、青の数も引く
	if (d > b) {
		ans = (c * a) - (d - b);
	}
	else {
		ans = c * a;
	}


	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] a = sc.next().split("");
		int i = 0;
		for(String b : a) {
			if(b.equals("1")) {
				i++;
			}
		}
		System.out.println(i);
	}
}

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

typedef long long ll;

int N, W;
vector<pair<int, int>> arr;
ll dp [101][100001];

ll solve(int i, int w) {
    if(i >= N)
        return 0;
    if(w >= W)
        return 0;
    if(~dp[i][w])
        return dp[i][w];

    dp[i][w] = solve(i+1, w);
    if(w+arr[i].second <= W)
        dp[i][w] = max(dp[i][w], arr[i].first+solve(i+1, w+arr[i].second));

    return dp[i][w];
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    cin >> N >> W;
    memset(dp, -1, sizeof dp);
    arr = vector<pair<int, int>>(N);
    for(int i = 0; i < N; i++) {
        int x, w; cin >> x >> w;
        arr[i] = {w, x};
    }

    cout << solve(0, 0) << "\n";
    
    return 0;
}

Measured memory_bytes: 82364
fn main() {
    // input
    // let one = read_vec::<u64>();
    // N
    let n = read_line::<usize>();
    // A
    let a = read_vec::<usize>();

    let mut ans = vec![0.to_string(); n];

    for (i, now) in a.iter().enumerate() {
        ans[*now - 1] = (i + 1).to_string();
    }
    println!("{}", ans.join(" "));
}

#[allow(dead_code)]
fn read_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 11004
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, XY):
    from math import sqrt, factorial
    road_map = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            road_map[i][j] = sqrt((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2)

    def dfs(now_town, visited, distance):
        visited[now_town] = 1
        if sum(visited) == N:
            return distance
        d = 0
        for i in range(N):
            if visited[i] == 0:
                d += dfs(i, visited.copy(), distance + road_map[now_town][i])
        return d

    sum_distance = 0
    for i in range(N):
        sum_distance += dfs(i, [0] * N, 0)

    print(sum_distance / factorial(N))


if __name__ == '__main__':
    # S = input()
    N = int(input())
    XY = []
    for _ in range(N):
        XY.append([int(i) for i in input().split()])
    solve(N, XY)


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

int main() {
	int64_t x,a,b;

	cin >>x;
	for(int64_t i=-1000;i<1000;i++){
		int flag = 0;
		for(int64_t j=-1000;j<1000;j++){
			a = i*i*i*i*i;
			b = j*j*j*j*j;
			if(a-b==x){
				cout << i << " " << j << endl;
				flag = 1;
			}
		}
		if(flag == 1){
			break;
		}
	}
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

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

		String[] a = new String[n];
		String[] b = new String[m];

		for (int i = 0; i < n; i++) {
			a[i] = sc.next();
		}

		for (int i = 0; i < m; i++) {
			b[i] = sc.next();
		}

		int i;
		for(i = 0; i < n-m+1; i++) {
			int j;
			for(j = 0; j < n-m+1; j++) {
				int k;
				for(k = 0; k < m; k++) {
					if(!b[k].equals(a[i+k].substring(j,  j+m))) {
						break;
					}
				}
				if(k >= m) {
					System.out.println("Yes");
					System.exit(0);
				}
				
			}
			
		}
		
		System.out.println("No");		

	}
}



Measured memory_bytes: 23636
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main(){
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let S = iter.next().unwrap().chars().collect::<Vec<_>>();
    //let N = iter.next().unwrap().parse::<usize>().unwrap();
    //let M = iter.next().unwrap().parse::<usize>().unwrap();
    let N = S.len();
    let mut a = (0..N+1).map(|_| -1).collect::<Vec<_>>();
    let mut p = '>';
    for (i,&s) in S.iter().enumerate(){
        if p == '>' && s == '<'{
            a[i] = 0;
        }
        p = s;
    }
    if S[N-1]=='>'{
        a[N] = 0;
    }
    for (i,&s) in S.iter().enumerate(){
        if s == '<' && a[i]!=-1{
            a[i+1] = a[i]+1;
        }
    }
    for i in 0..N{
        let i = N-i-1;
        let s = S[i];
        if s == '>' && a[i+1]!=-1{
            a[i] = max(a[i],a[i+1]+1);
        }
    }
    println!("{}",a.iter().sum::<i64>());
}


Measured memory_bytes: 10492
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	int n;
	cin >> n;
	cout << n * 800 - (n / 15) * 200 << endl;

	return 0;
}


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

int main()
{
  int n, a, b, count = 0;
  cin >> n >> a >> b;

  for (int i = 1; i <= n; i++)
  {
    if (i < 10 && a <= i && i <= b)
    {
      count += i;
      continue;
    }

    int buf = i;
    int dig, S = 0;

    while (buf)
    {
      dig = buf % 10;
      S += dig;
      buf /= 10;
    }

    if (a <= S && S <= b)
    {
      count += i;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   lli A,B,C,L,R,N,M,K,X=0,Y=0,sum=0,num=0,flag=0;string S,T,O;
   cin >> S >> T >> O;
   A=S.size();
   B=T.size();
   C=O.size();
   N=1;
   M=0;
   K=0;
   flag=S[0]-96;
   while(INF){
      if(flag==1){
         if(N==A){
         Out("A");
         break;
      }
         flag=S[N]-96;
         N++;
      }
      else if(flag==2){
         if(M==B){
         Out("B");
         break;
      }
         flag=T[M]-96;
         M++;
      }
      else{
         if(K==C){
         Out("C");
         break;
         }
         flag=O[K]-96;
         K++;
      }
   }
}

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

int main(void){
  vector<int> num(3);
  int k, i;
  cin >> num.at(0);
  cin >> num.at(1);
  cin >> num.at(2);
  cin >> k;

  sort(num.begin(), num.end());
  for(i = 0; i < k; i++){
    num[2] *= 2;
  }
  cout << num[0] + num[1] + num[2] << 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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)


int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(ALL(A));
    int ok = A[N-1], ng = 0;
    while (abs(ok-ng) > 1) {
        int mid = (ok+ng)/2;
        int cnt = 0;
        int tmp = N-1;
        while (cnt <= K && tmp >= 0 && A[tmp] > mid) {
            cnt += A[tmp]/mid-1;
            if(A[tmp]%mid) cnt++;
            tmp--;
        }
        if (cnt <= K) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}


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

int main(){
    string S,T;
    cin >> S;

    int endPos = S.length()-1;
    bool canTransform = true;

    while(1){
        if(endPos >= 4){
            string temp = S.substr(endPos-4, 5);
            if(temp == "dream" || temp == "erase"){
                endPos -= 5;
                continue;
            }
        }
        if(endPos >= 5){
            string temp = S.substr(endPos-5, 6);
            if(temp == "eraser"){
                endPos -= 6;
                continue;
            }
        }
        if(endPos >= 6){
            string temp = S.substr(endPos-6, 7);
            if(temp == "dreamer"){
                endPos -= 7;
                continue;
            }
        }
        if(endPos == -1){
            cout << "YES\n";
        }else{
            cout << "NO\n";
        }
        break;
    }




}




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

int main() {
	// your code goes here
	int H,W;
	cin >>H >>W;
	
	char mine[H][W];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> mine[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(mine[i][j]!='#'){
				int cnt=0;
				for(int k=-1;k<=1;k++){
				for(int l=-1;l<=1;l++){
					if(i+k>=0 && i+k<H && j+l>=0 && j+l<W){
					if(mine[i+k][j+l]=='#'){
						cnt++;
					}
					}
				}
				}
				cout<<cnt;
			}else{cout<<'#';}
		}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
public class Main {
	
	public void run(java.util.Scanner sc, java.io.PrintStream out) {
		for (;;) {
			final int M = sc.nextInt();
			final int T = sc.nextInt();
			final int P = sc.nextInt();
			final int R = sc.nextInt();
			if (M == 0 && T == 0 && P == 0 && R == 0) break ;
			
			final Record[] records = new Record[R];
			for (int i = 0; i < R; ++i) {
				final int m = sc.nextInt();
				final int t = sc.nextInt();
				final int p = sc.nextInt();
				final int j = sc.nextInt();
				records[i] = new Record(m, t, p, j);
			}
			
			final Team[] teams = new Team[T];
			for (int i = 1; i <= T; ++i)
				teams[i - 1] = new Team(i);
			for (int i = 0; i < R; ++i) {
				if (records[i].status != 0)
					continue ;
				teams[records[i].team - 1].solved += 1;
				teams[records[i].team - 1].penalties += records[i].time;
				for (int j = 0; j < i; ++j) {
					if (records[j].team == records[i].team && records[j].problem == records[i].problem)
						teams[records[i].team - 1].penalties += 20;
				}
			}
			java.util.Arrays.sort(teams);
			out.print(teams[0].id);
			for (int i = 1; i < T; ++i) {
				if (teams[i - 1].solved == teams[i].solved && teams[i - 1].penalties == teams[i].penalties)
					out.print('=');
				else
					out.print(',');
				out.print(teams[i].id);
			}
			out.println();
		}
	}

	public static void main(String[] args) {
		(new Main()).run(new java.util.Scanner(System.in), System.out);
	}

	private static class Team implements Comparable<Team> {
		public final int id;
		public int solved;
		public int penalties;
		public Team(int id) {
			this.id = id;
			this.solved = 0;
			this.penalties = 0;
		}
		@Override
		public int compareTo(Team o) {
			if (this.solved > o.solved)
				return -1;
			else if (o.solved > this.solved)
				return 1;
			if (this.penalties < o.penalties)
				return -1;
			else if (o.penalties < this.penalties)
				return 1;
			if (this.id > o.id)
				return -1;
			else if (o.id > this.id)
				return 1;
			return 0;
		}
	}
	
	private static class Record {
		public final int time;
		public final int team;
		public final int problem;
		public final int status;
		public Record(int time, int team, int problem, int status) {
			this.time = time;
			this.team = team;
			this.problem = problem;
			this.status = status;
		}
	}
	
}

Measured memory_bytes: 77272
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define N 200005
#define M 30005
#define ll long long 
#define INF 0x3f3f3f3f
#define PI 3.1415926535
#define EPS 1e-6
inline ll rd()
{
	ll f=1ll,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-f;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
int n;
ll k;
ll a[N],f[N],b[N];
bool cmp(int p,int q)
{
	return p>q;
}
bool check(ll x)
{
	for(int i=1;i<=n;i++)
		b[i]=x/f[i];//b[i]是每个人减少x 所应该减少的a[]的数量下取整 
	ll r=0;
	for(int i=1;i<=n;i++)
		r+=max(0ll,a[i]-b[i]);
	return r<=k;
}
int main()
{
	scanf("%d",&n);k=rd();
	for(int i=1;i<=n;i++)
		a[i]=rd();
	for(int i=1;i<=n;i++)
		f[i]=rd();
	sort(a+1,a+n+1);
	sort(f+1,f+n+1,cmp);
	ll l=0,r=(ll)1e12;//1e6*1e6 
	while(l+1<=r)
	{
		ll mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",l);
    return 0;
}

Measured memory_bytes: 4992
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int[] c = new int[n - 1], s = new int[n - 1], f = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            c[i] = scanner.nextInt();
            s[i] = scanner.nextInt();
            f[i] = scanner.nextInt();
        }

        for (int i = 0, time = 0; i < n - 1; i++, time = 0) {
            for (int j = i; j < n - 1; j++)
                time = Math.max(s[j], time % f[j] == 0 ? time : time + f[j] - time % f[j]) + c[j];
            System.out.println(time);
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 27968
#include <bits/stdc++.h>
using namespace std;
int n;
struct xy {
    vector<int> x;
    vector<int> y;
};

int main() {
    cin >> n;
    vector<int> a(n);
    vector<xy> axy(n);
    for(int i = 0; i < n; ++i) {
        cin >> a.at(i);
        for(int j = 0; j < a.at(i); ++j) {
            int x, y;
            cin >> x >> y;
            x--;
            axy.at(i).x.push_back(x);
            axy.at(i).y.push_back(y);
        }
    }

    int max = 0;

    for(int bit = 0; bit < (1<<n); ++bit) {
        bool ok = true;
        int cnt = 0;
        vector<int> cond(n,0);
        for(int i = 0; i < n; ++i) {
            if(bit & (1<<i)) {
                cnt++;
                cond.at(i) = 1;
            }
        }
        /*for(int l = 0; l < n; ++l) {
            cout << cond.at(l) << " ";
        }*/
        // cout << "cnt" << cnt << endl;
        for(int j = 0; j < n; ++j) {
            bool flg = true;
            if(cond.at(j)) {
                int alen = a.at(j);
                // cout << "alen" << alen << endl;
                for(int k = 0; k < alen; ++k) {
                    // cout << axy.at(j).y.at(k) << " " << cond.at(axy.at(j).x.at(k)) << endl;
                    if(axy.at(j).y.at(k) != cond.at(axy.at(j).x.at(k))){
                        ok = false;
                        flg = false;
                        break;
                    }
                }
                if(!flg) break;
            }
        }
        if(ok) {
            if(max < cnt) {
                max = cnt;
                // cout << "ans" << max << endl;
            }
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
int main()
{
	string s;
	cin>>s;
	for(auto c:s)
	{
		if(c=='1') cout<<9;
		else if(c=='9') cout<<1;
		else cout<<c;
	}
	cout<<Endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int r=0,b=0,g=0;
    long long sum;
    // int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
        r++;
        if(s[i]=='G')
        g++;
        if(s[i]=='B')
        b++;

    }
    sum=(long long)g*(long long)r*b;
    for(int i=1;i<n;i++)
    {
        for(int k=0;(k+2*i)<n;k++)
        {
            if(s[k]!=s[k+i] && s[k+2*i]!=s[k+i] && s[k]!=s[k+2*i])
            {
                sum--;
            }
        }
    }

    cout<<sum;
    return 0;
}

Measured memory_bytes: 3660
/*                   
                                             ::                     ::       
                                             ':                     :        
                                              :.                    :        
                                           ;' ::                   ::  '     
                                          .'  ';                   ;'  '.    
                                         ::    :;                 ;:    ::   
                                         ;      :;.             ,;:     ::   
                                         :;      :;:           ,;"      ::   
                                         ::.      ':;  ..,.;  ;:'     ,.;:   
                                          "'"...   '::,::::: ;:   .;.;""'    
                                              '"""....;:::::;,;.;"""         
                                          .:::.....'"':::::::'",...;::::;.   
                                         ;:' '""'"";.,;:::::;.'""""""  ':;   
                                        ::'         ;::;:::;::..         :;  
                                       ::         ,;:::::::::::;:..       :: 
                                       ;'     ,;;:;::::::::::::::;";..    ':.
                                      ::     ;:"  ::::::"""'::::::  ":     ::
                                       :.    ::   ::::::;  :::::::   :     ; 
                                        ;    ::   :::::::  :::::::   :    ;  
                                         '   ::   ::::::....:::::'  ,:   '   
                                          '  ::    :::::::::::::"   ::       
                                             ::     ':::::::::"'    ::       
                                             ':       """""""'      ::       
                                              ::                   ;:        
                                              ':;                 ;:"        


                                                     P_r_A_d_Y
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
const int N = 300005;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
void cs(int &x)
{
  cout<<"Case #"<<x<<": ";
}
bool cmp(int a,int b)
{
  return a>b;
}
int32_t main()
{
  fastIO;
  // int t;cin>>t;
  // int x=1;
  // while(t--)
  // {
     int n,d;cin >> n >> d;
     
     int c=0;
     for(int i=0;i<n;i++)
     {
      int x,y;cin >> x>> y;
      if(x*x + y*y <= d*d)
        c++;
     }
     cout<<c<<endl;

  //}
  return 0;
}

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

bool cmp(pair<int, ll> a, pair<int, ll> b)
{
    return a.second > b.second;
}

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

    int n, m;
    cin >> n >> m;

    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    vector<pair<int, ll>> bc(m);
    rep(i, m) cin >> bc[i].first >> bc[i].second;
    sort(bc.begin(), bc.end(), cmp);

    int p = 0;
    rep(i, m)
    {
        if (p + bc[i].first - 1 < n)
        {
            if (a[p + bc[i].first - 1] < bc[i].second)
            {
                forx(j, p, p + bc[i].first) a[j] = bc[i].second;
                p += bc[i].first;
                continue;
            }
            else
            {
                while (a[p] < bc[i].second)
                {
                    a[p] = bc[i].second;
                    p++;
                }
                break;
            }
        }
        else
        {
            while (p < n && a[p] < bc[i].second)
            {
                a[p] = bc[i].second;
                p++;
            }
            break;
        }
    }
    ll ans = 0;
    for (auto x : a)
        ans += x;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
import math
def isprime(x):
    if x==2:
        return 1
    if x<2 or x%2==0:
        return 0
    i=3
    while i<=math.sqrt(x):
        if x%i==0:
            return 0
        i=i+2
    return 1

cnt=0
n=int(input())
A=[0 for i in range(n)]
for i in range(n):
    A[i]=int(input())

for i in range(n):
    if isprime(A[i]):
        cnt+=1
print(cnt)


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

int main() {
  int N,K;
  int y=1;
  cin >> N>>K;
  for(int i=0;i<N;i++){
    if (y*2<y+K) y*=2;
    else y+=K;}
  cout<<y<<endl;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    unordered_set<string> words;
    string old_s;
    cin >> old_s;
    words.insert(old_s);
    bool result=true;
    for(int i=0; i<n-1; ++i){
        string s;
        cin >> s;
        result = result && (words.find(s)==words.end());
        result = result && (old_s.back()==s.front());
        words.insert(s);
        old_s=s;
    }
    if(result){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
    return 0;
}


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

int  a[1000],s[1000];

int main(){
	int n, ans=0;
	
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		s[a[i]]=1;
	}
	
	for(int i=1;i<=100;i++){
		ans+=s[i];
	}
	
	cout<<ans;
	return 0;
}

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

int main(){
	bool is_prime[1000000];

	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}

	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n_prime[1000000];

	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i]=cnt;
	}

	while(true){
		int n;
		cin>>n;

		if(cin.eof())
			break;

		cout<<n_prime[n]<<endl;
	}
	return 0; 
}

Measured memory_bytes: 7864
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {
	int r,g,b; cin >> r >> g >> b;

	if ((10 * g + b) % 4 == 0) {
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}


	return 0;
}


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


public class Test
{
	public static int cnt;
	static Test()
	{
		Test.cnt = 0;
	}
	public static void Main( )
	{
		var n = int.Parse( Console.ReadLine().Trim() );
		var A = Console.ReadLine().Trim().Split().Select( x => int.Parse( x ) ).ToArray();
		
		MergeSort( A, 0, n );
		Console.WriteLine( String.Join( " ", A) );
		Console.WriteLine( "{0}", Test.cnt );
		
		
		return;
	}
	public static void Merge( int[] A, int left, int mid, int right )
	{
		
		int n1 = mid - left;
		int n2 = right - mid;
		
		int[] L = new int[ n1+1 ];
		int[] R = new int[ n2+1 ];
		
		int i,j;
		for( i=0; i<n1; i++ ) {
			L[i] = A[left+i];
		}
		for( i=0; i<n2; i++ ) {
			R[i] = A[mid+i];
		}
		
		const int SENTINEL = 1000000001;
		L[n1] = SENTINEL;
		R[n2] = SENTINEL;

		i = 0;
		j = 0;
		int k;
		for( k = left; k<right; k++ )  {
			Test.cnt++;
			if( L[i] <= R[j] ) {
				A[k] = L[i];
				i = i+1;
			} else {
				A[k] = R[j];
				j = j+1;
			}
		}
		
		return;
	}
	public static void MergeSort( int[] A, int left, int right )
	{
		
		if( left+1 < right ) {
			int mid = (left+right)/2;
			MergeSort( A, left, mid );
			MergeSort( A, mid, right );
			Merge( A, left, mid, right );
		}
		
		return;
	}
}


Measured memory_bytes: 88908
use std::io;
use std::cmp;

fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.trim().split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

fn main(){
    let n = read_ints()[0];
    let xs = read_ints();
    let s : i64 = xs.iter().sum();
    
    let mut m = xs.iter().fold(0,|x,&y| cmp::max(x,y)) * n;
    let mut a : i64 = 0;
    
    for (idx,x) in xs.iter().enumerate(){
        if idx == xs.len() -1{
            break;
        }
        a += *x;
        m = cmp::min(m,(s - 2*a).abs());
    }
    println!("{}",m);
}



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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    int t = 0;
    for (int i = 1; i <= n; i++) {
        t += i;
    }

    cout << t << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
int d[31][31];
int a[501][501];
int b[3][31];

int main() {
	// D , D , 앳코더 1회 ㄱ? 
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, c; cin >> n >> c;

	for (int i = 1; i <= c; i++) {
		for (int j = 1; j <= c; j++) {
			cin >> d[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			int x = (i + j) % 3;
			for (int k = 1; k <= c; k++) {
				b[x][k] += d[a[i][j]][k];
			}
		}
	} // b[i][j] = i를 k개의 색깔로 바꾸는데 드는 비용 

	ll ans = 999999999999;
	for (int i = 1; i <= c; i++) {
		for (int j = 1; j <= c; j++) {
			for (int k = 1; k <= c; k++) {
				if (i == j || i == k || j == k)continue;
				ans = min(ans, (ll)b[0][i] + (ll)b[1][j] + (ll)b[2][k]);
			}
		}
	}
	cout << ans << '\n';
	




}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<bitset<30>> a(n), b(n);
    bitset<30> x;
    for (auto i : irange(0L, n)) {
        int64_t aa;
        cin >> aa;
        a[i] = aa;
        b[i] = ((aa - 1) ^ aa);
        x ^= aa;
    }

    int64_t ans = 0;
    for (auto i : irange(0L, 30L) | reversed) {
        bitset<30> t;
        for (auto j : irange(0L, n)) {
            if (b[j][i]) {
                t = b[j];
                break;
            }
        }

        if (t.none()) {
            continue;
        }

        if (x[i]) {
            ++ans;
            x ^= t;
        }

        for (auto j : irange(0L, n)) {
            if (b[j][i]) {
                b[j] ^= t;
            }
        }
    }

    if (!x.none()) {
        ans = -1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k; cin >> n >> k;
	int a = 0, b = 0;
	rep(i, n) {
		if ((i+1)%k == 0)a++;
		else if (k % 2 == 0 && (i+1)%k == k / 2)b++;
	}
	cout << a * a*a + b * b*b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;



int main(int argc, char* argv[])
{
    char str[1205]={0};
    while( scanf("%s", str ) && str[0]!='0' ) {
        int sum=0;
        int len=strlen(str);
        int i;
        for(i=0; i<len; i++) sum+=(str[i]-'0');
        printf("%d\n", sum);
    }

    return 0;
}



Measured memory_bytes: 2684
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxx = 100000 + 10;
struct Node {
	int key;
	Node *prev, *next;
};

Node *nil;

// ?????¨????§????
void init() {
	nil = (Node *)malloc(sizeof(Node));
	//C++ nil = new Node();
	nil->next = nil;
	nil->prev = nil;
}

// ????????¨????´¢?????????key????????? O(n)
Node* listSearch(int key) {
	// ????????¨??´??????????§???????
	Node *cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

// ?????°?????¨
void printList() {
	Node *cur = nil->next;
	int flag = 0;
	while (cur != nil) {
		if (flag++ > 0)
			printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

// ????????????t
void deleteNode(Node *t) {
	// t?????´??????????????????
	if (t == nil)
		return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
	//C++ delete(t);
}

// ????????´??????
void deleteFirst() {
	deleteNode(nil->next);
}

// ???????°???????
void deleteLast() {
	deleteNode(nil->prev);
}

// ???????????????key O(n)
void deleteKey(int key) {
	deleteNode(listSearch(key));
}

// ??¨?????¨??´??¨??????????´?key
void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	//C++ Node *x = new Node();
	x->key = key;

	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}
int main() {
	int n, key, size = 0;
	char op[20];
	scanf("%d", &n);
	getchar();
	// ????§?????????¨
	init();
	for (int i = 0; i < n; i++) {
		scanf("%s %d", op, &key);
		if (op[0] == 'i') {
			insert(key);
			size++;
		}else {
			if (strlen(op) > 6) {
				if (op[6] == 'F') {//????????´??????
					deleteFirst();
				}else {//???????°???????
					deleteLast();
				}
			}
			else { //????????????
				deleteKey(key);
			}
			size--;
		}
	}
	printList();
	return 0;
}

Measured memory_bytes: 34348
import java.util.*;

public class Main {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean[] primes = new boolean[1000000];
        primes[0] = true;
        primes[1] = true;
        for (int i = 2; i < primes.length; i++) {
            if (primes[i]) {
                continue;
            }
            for (int j = 2; j * i < primes.length; j++) {
                primes[i * j] = true;
            }
        }
        StringBuilder sb = new StringBuilder();
        while(true) {
            int a = sc.nextInt();
            int d = sc.nextInt();
            int n = sc.nextInt();
            if (a == 0 && d == 0 && n == 0) {
                break;
            }
            int count = 0;
            int value = 0;
            for (int i = 0; count < n && a + d * i < 1000000; i++) {
                if (!primes[a + d * i]) {
                    count++;
                    value = a + d * i;
                }
            }
            sb.append(value).append("\n");
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 29236
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
a = LIST()
a.sort()
print(sum(a[N::2]))

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

using namespace std;

int main() {
    while(1) {
        string s;
        cin >> s;
        if (s == "#") break;
        int y, m, d;
        cin >> y >> m >> d;
        if ((y == 31 && m >= 5) || (y > 31)) {
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        } else {
            cout << "HEISEI " << y << " " << m << " " << d << endl;
        }
    }
}


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

public class Program {
	public static void Main() {
		new Calc().calc();
	}
	public class Calc {
		private List<Tuple<int, int>> checkpoints, st;

		public Calc() {
			st = new List<Tuple<int, int>>();
			checkpoints = new List<Tuple<int, int>>();
		}
		public void calc() {
			string[] str = Console.ReadLine().Split(' ');
			int N = int.Parse(str[0]);
			int M = int.Parse(str[1]);
			for (int i = 0; i < N; i++) {
				var line = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
				st.Add(new Tuple<int, int>(line[0], line[1]));
			}
			for (int i = 0; i < M; i++) {
				var line = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
				checkpoints.Add(new Tuple<int, int>(line[0], line[1]));
			}
			foreach (var item in st) {
				var index = checkpoints.Select(
					_ => Math.Abs(item.Item1 - _.Item1) + Math.Abs(item.Item2 - _.Item2))
				.Select((val, idx) => new { V = val, I = idx })
				.Aggregate((min, work) => (min.V <= work.V) ? min : work).I;
				Console.WriteLine(index+1);
			}
		}
	}
}

Measured memory_bytes: 13268
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Sun and Moon
// 2013/03/23
public class Main{
	Scanner sc=new Scanner(System.in);

	long INF=1L<<60;

	int n;
	long[] as, bs;

	void run() throws Exception{
		n=sc.nextInt();
		as=new long[n];
		bs=new long[n];
		for(int i=0; i<n; i++){
			bs[i]=sc.nextLong();
			as[i]=sc.nextLong();
		}
		solve();
	}

	void solve() throws Exception{
		if(n==0){
			println("Yes 1");
			return;
		}
		int m=5;

		long[] ps=new long[m];
		ps[0]=BigInteger.valueOf((int)1e3).nextProbablePrime().longValue();
		for(int i=1; i<m; i++){
			ps[i]=BigInteger.valueOf(ps[i-1]+1).nextProbablePrime().longValue();
		}

		for(int x=1; x<=1000; x++){
			int mod1=(int)ps[0], mod2=(int)ps[1];
			if(f(x, mod1)==0&&df(x, mod1)==0&&f(x, mod2)==0&&df(x, mod2)==0){
				println("Yes "+x);
				return;
			}
		}

		long min=INF;
		long[] A=new long[m], B=new long[m];
		fill(A, 1);

		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] list=new ArrayList[m];
		for(int i=0; i<m; i++){
			list[i]=candidate((int)ps[i]);
		}
		for(int x0 : list[0]){
			for(int x1 : list[1]){
				for(int x2 : list[2]){
					for(int x3 : list[3]){
						for(int x4 : list[4]){
							B[0]=x0;
							B[1]=x1;
							B[2]=x2;
							B[3]=x3;
							B[4]=x4;
							long res=linearCongruence(A, B, ps);
							if(res!=-1&&res>0){
								min=min(min, res);
							}
						}
					}
				}
			}
		}
		if(min<INF){
			println("Yes "+min);
		}else{
			println("No");
		}
	}

	ArrayList<Integer> candidate(int p){
		ArrayList<Integer> list=new ArrayList<Integer>();
		for(int i=0; i<p; i++){
			if(f(i, p)==0&&df(i, p)==0){
				list.add(i);
			}
		}
		return list;
	}

	long linearCongruence(long[] A, long[] B, long[] M){
		long x=0, m=1;
		for(int i=0; i<A.length; i++){
			long a=A[i]*m, b=B[i]-A[i]*x, d=gcd(M[i], a);
			if(b%d!=0)
				return -1;
			x+=m*(mulMod(b/d, invMod(a/d, M[i]/d), (M[i]/d)));
			m*=M[i]/d;
		}
		return x%m;
	}

	long powMod(long x, long k, int mod){
		long res=1;
		for(; k!=0; k>>>=1){
			if((k&1)==1){
				res=res*x%mod;
			}
			x=x*x%mod;
		}
		return res;
	}

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

	long invMod(long a, long mod){
		return powMod(a, mod-2, mod);
	}

	long mulMod(long x, long y, long mod){
		long res=0;
		for(; y!=0; y>>>=1){
			if((y&1)==1){
				res=(res+x)%mod;
			}
			x=(x+x)%mod;
		}
		return res;
	}

	long powMod(long x, long k, long mod){
		long res=1;
		for(; k!=0; k>>>=1){
			if((k&1)==1){
				res=mulMod(res, x, mod);
			}
			x=mulMod(x, x, mod);
		}
		return res;
	}

	long f(long x, int mod){
		long val=0;
		for(int i=0; i<n; i++){
			val=(val+as[i]%mod*powMod(x, bs[i], mod)%mod)%mod;
		}
		return val;
	}

	long df(long x, int mod){
		long val=0;
		for(int i=0; i<n; i++){
			if(bs[i]>0){
				val=(val+bs[i]%mod*as[i]%mod*powMod(x, bs[i]-1, mod)%mod)%mod;
			}
		}
		return val;
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args) throws Exception{
		new Main().run();
	}
}

Measured memory_bytes: 26924
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1_6_B
{
    class Program
    {
        static void Main(string[] args)
        {

            //手持ちのトランプn枚から、52-n枚のトランプを出力する
            //1行目 n：手持ちのトランプの枚数
            //2行目以降 (文字 整数)：S,H,C,D(絵柄)　カードのランク
            //出力はランク < 絵柄、　S > H > C > D、1 > 13

            int n = int.Parse(Console.ReadLine());              //1行目の入力 枚数をint型変数のnに取得

            //カードのランクの入った配列(cardRank)
            int[] RankS = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
            int[] RankH = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
            int[] RankC = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
            int[] RankD = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };

            for (int i = 0; i < n; i++)                         //以下の処理をn回繰り返す
            {
                string[] card = Console.ReadLine().Split(' ');  //2行目の入力を記号 ランクの配列として取得

                if (card[0] == "S")                             //カードがスペードの時
                {
                    //RankS配列からカードのランク(card[1])を指定し、取り除く
                    RankS[(int.Parse(card[1]))-1] = 0;
                }
                else if (card[0] == "H")                        //カードがハートの時
                {
                    RankH[(int.Parse(card[1])) - 1] = 0;
                }
                else if (card[0] == "C")                        //カードがクローバーの時
                {
                    RankC[(int.Parse(card[1])) - 1] = 0;
                }
                else if (card[0] == "D")                        //カードがダイヤの時
                {
                    RankD[(int.Parse(card[1]))-1] = 0;
                }
                else
                { }
            }

            //配列をリストに変換し、から要素を削除して配列に戻す
            List<int> listS = new List<int>(RankS);             //配列をリストに変換
            listS.RemoveAll(item => item == 0);                 //0を一括削除
            var listS2 = listS.ToArray();                       //リストを配列に
            //配列の中身を表示する
            foreach (var a in listS2) Console.WriteLine("S "+ a);

            List<int> listH = new List<int>(RankH);
            listH.RemoveAll(item => item == 0);
            var listH2 = listH.ToArray();
            foreach (var a in listH2) Console.WriteLine("H " + a);

            List<int> listC = new List<int>(RankC);             //配列をリストに変換
            listC.RemoveAll(item => item == 0);   //nullを一括削除
            var listC2 = listC.ToArray();                       //リストを配列に
            foreach (var a in listC2) Console.WriteLine("C " + a);

            List<int> listD = new List<int>(RankD);             //配列をリストに変換
            listD.RemoveAll(item => item == 0);   //nullを一括削除
            var listD2 = listD.ToArray();                       //リストを配列に
            foreach (var a in listD2) Console.WriteLine("D " + a);

        }
    }
}



Measured memory_bytes: 15928
H, W = map(int, input().split())

S = [input() for _ in range(H)]
X = [[[int(1e9), 0] for i in range(W)] for j in range(H)]
p = [[0, 0]]
if S[0][0] == '#':
  X[0][0][0], X[0][0][1] = 1, 1
else:
  X[0][0][0], X[0][0][1] = 0, 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      X[i][j][1] = 1
for m in range(H+W-2):
  n = len(p)
  for i in range(n):
    x = p[i][:]
    if x[0] < H - 1:
      p.append([x[0]+1, x[1]])
    if x[0] == 0 and x[1] < W - 1:
      p.append([x[0], x[1]+1])
  p = p[n:]
  n = len(p)
  for i in range(n):
    x = p[i][:]
    if x[0] > 0 and x[1] > 0:
      X[x[0]][x[1]][0] = min(X[x[0]-1][x[1]][0] + (1-X[x[0]-1][x[1]][1])*X[x[0]][x[1]][1], X[x[0]][x[1]-1][0] + (1-X[x[0]][x[1]-1][1])*X[x[0]][x[1]][1])
    elif x[0] == 0 and x[1] > 0:
      X[x[0]][x[1]][0] = X[x[0]][x[1]-1][0] + (1-X[x[0]][x[1]-1][1])*X[x[0]][x[1]][1]
    elif x[0] > 0 and x[1] == 0:
      X[x[0]][x[1]][0] = X[x[0]-1][x[1]][0] + (1-X[x[0]-1][x[1]][1])*X[x[0]][x[1]][1]
print(X[H-1][W-1][0])

Measured memory_bytes: 4340