akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int min(int a, int b){
        if(a < b) return a;
        else return b;
}

int main(){
        int n;
        scanf("%d", &n);
        int h[n];
        for(int i=0; i<n; i++) scanf("%d", &h[i]);

        int dp[n];
        for(int i=0; i<n; i++) dp[i] = 1e9;
        dp[0] = 0;

        for(int i=0; i<n; i++){
                if(i >= 1){
                        dp[i] = min(dp[i], dp[i-1] + abs(h[i-1]-h[i]));
                }
                if(i >= 2){
                        dp[i] = min(dp[i], dp[i-2] + abs(h[i-2]-h[i]));
                }
        }
        printf("%d\n", dp[n-1]);
        return 0;
}


Measured memory_bytes: 2464
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<queue>	
#include<functional>
#include<climits>
#include<tuple>
#include<utility>
#include<cassert>

using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
#define pb push_back
#define PB push_back
#define lb lower_bound
#define LB lower_bound
#define ub upper_bound
#define UB upper_bound


//constant
const int MOD = 1000000007;
const int INF = INT_MAX / 2-1;
const double EPS = 1e-9;
const int dx4[4] = { 1,0,-1,0 };
const int dy4[4] = { 0,1,0,-1 };

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

ll s;
ll f(int i, ll n) {
	if (n < i)
		return n;
	return f(i, floor(double(n) / i)) + n%i;

}

int main() {
	ll n;
	cin >> n;
	cin >> s;
	
	if (s > n) {
		cout << -1 << endl;
		return 0;
	}

	for(int i=2;i<1000000;i++) {
		if (f(i,n)==s) {
			cout << i << endl;
			return 0;
		}
	}
	if (n == s) {
		cout << s + 1 << endl;
		return 0;
	}
	for(int i=1000000;i>=1;i--){
		if ((n - s) % i == 0 && i <= s && i < (n - s) / i + 1 && s-i<(n-s)/i+1) {
				cout << (n - s) / i + 1 << endl;
			return 0;
		}


	}


	cout << -1 << endl;
	return 0;

}

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;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }			//最小公倍数(Least Common Multiple)


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

	int ans = 0;

	rep(i, 1250) {
		if (floor(i*0.08) == a && floor(i*0.1) == b) {
			ans = i;
			break;
		}
		if (i == 1249)
			ans = -1;
	}

	cout << ans << endl;



}

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

const int INF = 1e9;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> dp(1 << N, INF);
	dp[0] = 0;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		int v = 0;
		for (int j = 0; j < b; j++) {
			int c;
			cin >> c; --c;
			v |= 1 << c;
		}
		for (int s = 0; s < (1 << N); s++) {
			dp[s | v] = min(dp[s | v], dp[s] + a);
		}
	}
	cout << (dp.back() == INF ? -1 : dp.back()) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    ll d,sum=0;
    while(cin >> d){
        sum=0;
        for(int i=1;i<=(600/d)-1;i++){
            sum+=d*(i*d)*(i*d);
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
N = int(input())
S = str(N)
def f(s, p, x):
    if len(s) == 0:
        return 1 if x == 7 else 0
    if p:
        return f(s[1:], True, x | 1) + f(s[1:], True, x | 2) + f(s[1:], True, x | 4) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '8' or s[0] == '9':
        return f(s[1:], True, x | 1) + f(s[1:], True, x | 2) + f(s[1:], True, x | 4) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '7':
        return f(s[1:], True, x | 1) + f(s[1:], True, x | 2) + f(s[1:], False, x | 4) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '6':
        return f(s[1:], True, x | 1) + f(s[1:], True, x | 2) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '5':
        return f(s[1:], True, x | 1) + f(s[1:], False, x | 2) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '4':
        return f(s[1:], True, x | 1) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '3':
        return f(s[1:], False, x | 1) + (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '2' or s[0] == '1':
        return (f(s[1:], True, x) if x == 0 else 0)
    if s[0] == '0':
        return 0
ans = f(S, False, 0)
print(ans)


Measured memory_bytes: 3192
// 10min
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    char buffer[20];
    int  A, B, K;

    if (fgets(buffer, 20, stdin) != NULL) {
        A = atoi(strtok(buffer, " "));
        B = atoi(strtok(NULL, " "));
        K = atoi(strtok(NULL, " "));
    } else {
        return 1;
    }
    int max_num   = 0;
    if (A <= B) {
        max_num = A;
    } else {
        max_num = B;
    }

    int lcm_num = 0, lcm_value = 0;
    for (int i = max_num; 1 <= i; i--) {
        if (lcm_num != K) {
            if (A % i == 0 && B % i == 0) {
                lcm_num  += 1;
                lcm_value = i;
            }
        } else {
            break;
        }
    }
    printf("%d", lcm_value);
    return 0;
}

Measured memory_bytes: 128
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class v:
    def __init__(self, f):
        self.f = f
        self.v = None
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 

def f(i, H):
    B = format(i, "0" + str(H - 1) + "b")
    R = []
    left = 0
    right = 1
    for b in B:
        if b == "1":
            R.append((left, right))
            left = right
        right += 1
    R.append((left, right))
    
    return R


def g(S, H, W, K, block):
    wl = 0
    wr = 1
    res = 0
    while wr != W + 1:
        T = max(S[hr][wr] - S[hl][wr] - S[hr][wl] + S[hl][wl] for hl, hr in block)
        # print(wl, wr, T)
        if T > K:
            if wr - wl == 1:
                return 10 ** 10

            res += 1
            wl = wr - 1
            continue
        wr += 1
    
    return res + len(block) - 1


def main():
    H, W, K = read_values()
    C = [input() for _ in range(H)]

    S = [[0 for _ in range(W + 1)] for __ in range(H + 1)]
    for h in range(H):
        for w in range(W):
            r = int(C[h][w])
            S[h + 1][w + 1] = S[h][w + 1] + S[h + 1][w] - S[h][w] + r

    r = v(min)
    for i in range(1 << (H - 1)):
        block = f(i, H)
        t = g(S, H, W, K, block)
        r.ud(t)
    
    print(r)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 3564
#include <bits/stdc++.h>  // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n,k;
  cin>>n>>k;
  cout << n-k+1<< endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++)
    cin >> v.at(i);
  
  set<string> s;
  for (int i = 0; i < n; i++)
    s.insert(v.at(i));
  
  cout << s.size() << endl;
       
  return 0;
}

Measured memory_bytes: 25168
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

bool red[100010];
int num[100010];

int main(){
    int n, m;
    cin >> n >> m;
    red[0] = 1;
    rep(i, n) num[i] = 1;

    rep(i, m){
        int x, y;
        cin >> x >> y;
        x--, y--;
        if (red[x] && num[x] == 1) {
            num[x]--;
            num[y]++;
            red[x] = 0;
            red[y] = 1;
        }
        else if (red[x] && num[x] > 1) {
            num[x]--;
            num[y]++;
            red[y] = 1;
        }
        else {
            num[x]--;
            num[y]++;
        }
    }
    int cnt = 0;
    rep(i, n) if (red[i]) cnt++;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 4024
Xa, K, D = map(int, input().split())

X = abs(Xa)
Xs = X // D
Xm = X % D

if K < Xs:
#     print("A")
    print(abs(X-K*D))
# elif Xa == 0:
#     if K % 2 == 0:
#         print(0)
#     else:
#         print(D)
# elif Xm == 0:
#     if K % 2 == 0:
#         print(D)
#     else:
#         print(0)
elif ((K-Xs) % 2 == 0):
    print(abs(Xm))
else:
    print(abs(D-Xm))
# else:
# #     print(abs(D-K))
#     if ((K-Xs) % 2 == 0):
#         print(abs(D-K))
#     else:
#         print(abs(D-Xm))


Measured memory_bytes: 9040
#include <stdio.h>

int main(void)
{
 int a,b;

 scanf("%d %d", &a, &b) ;

 if( a > b ){
   printf("a > b\n");
 }else if( a < b ){
   printf("a < b\n");
 }else{
   printf("a == b\n");
 }

 return 0;
}

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


int main(){
  string s;
  cin >> s;
  int n=s.size();
  int ans=754;
  for(int i=0;i<n-2;++i){
    int cal;
    cal=(s[i]-'0')*100;
    cal+=(s[i+1]-'0')*10;
    cal+=(s[i+2]-'0');
    //cout << cal << endl;
    ans=min(ans,abs(cal-753));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3552
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ICPCCalculator solver = new ICPCCalculator();
        try {
            int testNumber = 1;
            while (true)
                solver.solve(testNumber++, in, out);
        } catch (UnknownError e) {
            out.close();
        }
    }

    static class ICPCCalculator {
        int n;
        String[] S;
        boolean[] visited;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            n = in.nextInt();
            if (n == 0) throw new UnknownError();
            S = new String[n];
            visited = new boolean[n];
            Arrays.fill(visited, false);
            for (int i = 0; i < n; i++) {
                S[i] = in.next();
            }
            if (n == 1) {
                out.println(S[0]);
                return;
            }
            out.println(dfs(0, 0, false));
        }

        private int dfs(int now, int dot, boolean ope) {
            int ans = ope ? 1 : 0;
            for (int i = now; i < n; i++) {
                if (S[i].length() <= dot) break;
                final char c = S[i].charAt(dot);
                if (Character.isDigit(c)) {
                    if (ope) {
                        ans *= c - '0';
                    } else {
                        ans += c - '0';
                    }
                } else if (c == '+' || c == '*') {
                    if (ope) {
                        ans *= dfs(i + 1, dot + 1, c == '*');
                    } else {
                        ans += dfs(i + 1, dot + 1, c == '*');
                    }
                } else if (c == '.') {
                    continue;
                } else {
                    throw new Error();
                }
            }
            return ans;
        }

    }
}

Measured memory_bytes: 30868
#include<iostream>
using namespace std;
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2 + 2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  for( int i = 0; i < n1; i++ )L[i] = A[left + i];
  for( int i = 0; i < n2; i++ )R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for ( int k = left; k < right; k++ ){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

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

int main(){
  int A[MAX], n, i;
  int m=1;
  cin>>n;
  for ( i = 0; i < n; i++) cin >> A[i];
  mergeSort(A, n, 0, n);
  for(int i=0;i<n;i++){
    if(A[i]<A[i+1])m++;
  }
  cout<<m<<endl;
  return 0;
}


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

int main()
{
    string S,T;
    int l1,l2,i;

    cin>>S;
    cin>>T;

    l1=S.size();
    l2=T.size();

    if(l1==(l2-1))
    {
        for(i=0; i<l1; i++)
        {
            if(S[i]!=T[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }

    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 3512
n = int(input())

chars = 'abcdefghijklmnopqrstuvwxyz'
def to26(n):
  if n <= 0:
    return ''
  mod = 26 if n % 26 == 0 else n % 26
  if n == mod:
    return chars[mod-1]
  n = int((n - mod) / 26)
  return to26(n) + chars[mod-1]

print(to26(n))

Measured memory_bytes: 9176
#include <stdio.h>
#include <vector>
#include <math.h>
#include <iostream>
 int main(){

     using namespace std;
     
     string s;
     int q;
     cin >> s >> q;
     
     int a, b;
     int count = 0;
     string d;
     
     for(int i=0; i<q; i++)
     {
         cin >> a;
         
         if(a == 1)
         {
//             //前後入れ替え
//             for(int j = 0; j < s.length() / 2; j++){
//                 char t = s[j];
//                 s[j] = s[s.length() - j - 1];
//                 s[s.length() - j - 1] = t;
//             }
             
             count++;
             
         } else {
             cin >> b >> d;
             
             if(b == 1)
             {
                 if(count % 2 == 0){
                 s.insert(0, d);
                 } else {
                     s.append(d);
                 }
                 
             } else {
                 if(count % 2 == 0)
                 {
                 s.append(d);
                 } else {
                     s.insert(0, d);
                 }
             }
         }
         
         
         
     }
     
     if(count % 2 == 1)
     {
         //前後入れ替え
         for(int j = 0; j < s.length() / 2; j++){
             char t = s[j];
             s[j] = s[s.length() - j - 1];
             s[s.length() - j - 1] = t;
         }
     }

     cout << s << endl;

     return 0;
    
}

Measured memory_bytes: 1028
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
string str_a,str_b;
int i;

int main(){
    cin >> str_a >> str_b;

    sort(str_a.begin(),str_a.end());
    sort(str_b.rbegin(),str_b.rend());
    
    str_a.push_back('0');
    str_b.push_back('0');
    
    for(i=0;!(str_a[i]=='0'||str_b[i]=='0');i++){
        if(str_a[i]>str_b[i]){
            cout <<"No";
            return 0;
        }else if(str_a[i]<str_b[i]){
            cout << "Yes";
            return 0;
        }
    }
    if(str_a[i]=='0'&&str_b[i]=='0')cout << "No";
    else if(str_a[i]=='0') cout << "Yes";
    else cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, D = MAP()
    if N%(2* D + 1)>0:
        print(N//(2* D + 1)+1)
    else:
        print(N//(2* D+ 1))

if __name__ == '__main__':
    main()


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

class dsu {
  int N;
  vector<int> PS;
public:
  dsu() : N(0) {}
  dsu(int n) : N(n), PS(n, -1) {}
  int merge(int a, int b) {
    assert(0 <= a && a < N);
    assert(0 <= b && b < N);
    int x = leader(a), y = leader(b);
    if (x == y) return x;
    if (-PS.at(x) < -PS.at(y)) swap(x, y);
    PS.at(x) += PS.at(y);
    PS.at(y) = x;
    return x;
  }
  bool same(int a, int b) {
    assert(0 <= a && a < N);
    assert(0 <= b && b < N);
    return leader(a) == leader(b);
  }
  int leader(int a) {
    assert(0 <= a && a < N);
    if (PS.at(a) < 0) return a;
    return PS.at(a) = leader(PS.at(a));
  }
  int size(int a) {
    assert(0 <= a && a < N);
    return -PS.at(leader(a));
  }
  vector<vector<int>> groups() {
    vector<int> B(N), S(N);
    for (int i = 0; i < N; i++) {
      B.at(i) = leader(i);
      S.at(B.at(i))++;
    }
    vector<vector<int>> ret(N);
    for (int i = 0; i < N; i++) {
      ret.at(i).reserve(S.at(i));
    }
    for (int i = 0; i < N; i++) {
      ret.at(B.at(i)).push_back(i);
    }
    ret.erase(
      remove_if(ret.begin(), ret.end(), [&](const vector<int>& v) { return v.empty(); }),
      ret.end()
    );
    return ret;
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> NG(N, 1);
  dsu D(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    NG.at(a)++, NG.at(b)++;
    D.merge(a, b);
  }
  for (int i = 0; i < K; i++) {
    int c, d;
    cin >> c >> d;
    c--, d--;
    if (D.same(c, d)) NG.at(c)++, NG.at(d)++;
  }
  for (int i = 0; i < N; i++) {
    cout << D.size(i) - NG.at(i) << "\n";
  }
}

Measured memory_bytes: 3956
#include <stdio.h>
#include <math.h>

int main(void){
  int n;
  scanf("%d", &n);
  long int ans = 1;
  
  for(int i = 1; i <= n; i++){
    ans = (ans * i) % (int)(pow(10, 9) + 7);
  }
  
  printf("%ld\n", ans);
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(x=1;x<=9;x++) for(y=1;y<=9;y++) {
		if(x*y==N) return _P("Yes\n");
	}
	cout<<"No"<<endl;
		
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w;
  while(cin>>h>>w){
    if(h==0)break;
    int d=h*h+w*w,ah=100,aw=100;
    for(int i=1;i<=150;i++)
      for(int j=i+1;j<=150;j++){
	int k=i*i+j*j,ad=ah*ah+aw*aw;
	if(((k==d&&i>h)||k>d)&&(ad>k||(k==ad&&ah>i)))ah=i,aw=j;
      }
    cout<<ah<<' '<<aw<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import sys

sys.setrecursionlimit(10995116)


def get_func():
    cache = {1: 1}

    def f(x):
        if x in cache:
            return cache[x]
        cache[x] = f(x // 2) * 2 + 1
        return cache[x]

    return f


h = int(input())
f = get_func()
print(f(h))


Measured memory_bytes: 2940
def main():
    for x in range(H):
        for y in range(W):
            if S[x][y] == ".":
                tmp = 0
                if x > 0 and S[x - 1][y] == "#":
                    tmp = tmp + 1
                if x < H - 1 and S[x + 1][y] == "#":
                    tmp = tmp + 1
                if y > 0 and S[x][y - 1] == "#":
                    tmp = tmp + 1
                if y < W - 1 and S[x][y + 1] == "#":
                    tmp = tmp + 1
                if x > 0 and y > 0 and S[x - 1][y - 1] == "#":
                    tmp = tmp + 1
                if x > 0 and y < W - 1 and S[x - 1][y + 1] == "#":
                    tmp = tmp + 1
                if x < H - 1 and y > 0 and S[x + 1][y - 1] == "#":
                    tmp = tmp + 1
                if x < H - 1 and y < W - 1 and S[x + 1][y + 1] == "#":
                    tmp = tmp + 1
                S[x][y] = str(tmp)

    for i in S:
        print("".join(i))


if __name__ == "__main__":
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    main()

Measured memory_bytes: 3188
# Problem C - Skill Up

# input
N, M, X = map(int, input().split())
book_list = []
for i in range(N):
    book = list(map(int, input().split()))
    book_list.append(book)

# initialization
price = float('INF')
is_ok = False

# pattern
pattern = []
for i in range(2**N):
    p = [0]*N
    for j in range(N):
        if (i>>j)&1==1:
            p[j] = 1
    pattern.append(p)

for p in pattern:
    tmp_sum = [0]*(M+1)
    is_finish = True
    for i in range(N):
        if p[i]==1:
            for j in range(M+1):
                tmp_sum[j] += book_list[i][j]
    # check
    for i in range(1, M+1):
        if not tmp_sum[i]>=X:
            is_finish = False
            break

    if is_finish:
        is_ok = True
        price = min(price, tmp_sum[0])

# output
if is_ok:
    print(price)
else:
    print(-1)


Measured memory_bytes: 9652
#include <stdio.h>
 int main(void){

    int i, j,H,W;
    while(scanf("%d %d",&H,&W)!=EOF){
     if(H==0&&W==0){
         break;
     }
     for ( i = 0; i < H; i++ ){
     for ( j = 0; j < W; j++ ){
         if(j==0||j==W-1||i==0||i==H-1){
             printf("#");
         } else {
             printf(".");
         }
     }
     printf("\n");
 }
     printf("\n");
 }
  return(0);
      
 }


Measured memory_bytes: 2084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
    int[] smallestDivisorOf;

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

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(f.readLine());
        int[] ar = new int[n];
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) {
            ar[i] = Integer.parseInt(tokenizer.nextToken());
        }

        smallestDivisorOf = new int[1000001];
        for (int i = 2; i < smallestDivisorOf.length; i++) {
            for (int j = i; j < smallestDivisorOf.length; j += i) {
                if (smallestDivisorOf[j] == 0) {
                    smallestDivisorOf[j] = i;
                }
            }
        }

        if (isPairwise(ar)) {
            out.println("pairwise coprime");
        } else if (isSetwise(ar)) {
            out.println("setwise coprime");
        } else {
            out.println("not coprime");
        }

        out.close();
    }

    private boolean isPairwise(int[] ar) {
        ar = Arrays.copyOf(ar, ar.length);
        HashSet<Integer> primes = new HashSet<Integer>();
        while (ar[0] != 1) {
            primes.add(smallestDivisorOf[ar[0]]);
            ar[0] /= smallestDivisorOf[ar[0]];
        }

        for (int i =  1; i < ar.length; i++) {
            HashSet<Integer> currentPrimes = new HashSet<Integer>();
            while (ar[i] != 1) {
                currentPrimes.add(smallestDivisorOf[ar[i]]);
                ar[i] /= smallestDivisorOf[ar[i]];
            }

            for (int j : currentPrimes) {
                if (primes.contains(j)) return false;
                primes.add(j);
            }
        }

        return true;
    }

    private boolean isSetwise(int[] ar) {
        int gcd = ar[0];
        for (int i = 1; i < ar.length; i++) {
            gcd = gcd(gcd, ar[i]);
        }

        return gcd == 1;
    }

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

Measured memory_bytes: 75868
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define re(i , n) for(Long i = 0; i < (Long)n ; i++)
#define rer(i, a, b) for (Long i = a, to = b; i < to; i++)

using namespace std;
typedef long long Long;
const Long MX=2e5 + 1;
const Long MOD=1000000007;
const Long MX2=9223372036854775806;
vector<Long> v(200),n(200);

void build(){
	re(i,200){
		v[i]=i*i*i*i*i;
		n[i]=-i*i*i*i*i;
	}
}

Long op(Long t){
	for(Long i=0;i<200;i++){
		if((i*i*i*i*i)==t){
			return i;
		}
		if((i*i*i*i*i)==-1*(t)){
			return -i;
		}
	}
	
	
}

int main(){
	ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	Long x;cin>>x;
	build();
	re(i,200){
		Long l1,l2;
		l1=x+v[i];
		bool hola=binary_search(v.begin(),v.end(),l1);
		bool hola2=binary_search(n.begin(),n.end(),l1);
		if(hola){
			cout<<op(l1)<<" "<<op(v[i]);
			return 0;
		}
		if(hola2){
			cout<<op(l1)<<" "<<op(v[i]);
			return 0;
		}
		l2=x+n[i];
		hola=binary_search(v.begin(),v.end(),l2);
		hola2=binary_search(n.begin(),n.end(),l2);
		if(hola){
			cout<<op(l2)<<" "<<op(n[i]);
			return 0;
		}
		if(hola2){
			cout<<op(l2)<<" "<<op(n[i]);
			return 0;
		}
	}
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using Pii = pair<int, int>;
using Vi = vector<int>;
using St = string;
using Ch = char;

const double pi = 3.1415926535;

void Main()
{
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i, n) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	int ans = 0;
	for (int i = 0; i < l.size(); i++) {
		for (int j = 0; j < l.size(); j++) {
			for (int k = 0; k < l.size(); k++) {
				if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) {
					break;
				}
				if (max(l[i], max(l[j], l[k])) < l[i] + l[j] + l[k] - max(l[i], max(l[j], l[k]))) {
					ans++;
				}
			}
		}		
	}
	cout << ans / 2 << endl;
}

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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i],a[i]--;
  int dist[n];
  memset(dist,-1,sizeof(dist));
  queue<int> q;
  q.push(0);
  dist[0]=0;
  while(!q.empty()){
    int p=q.front();q.pop();
    if(dist[a[p]]<0){
      dist[a[p]]=dist[p]+1;
      q.push(a[p]);
    }
  }
  cout<<dist[1]<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
#include <set>
#include <map>

#define FOR0(var, max) for (ul (var) = 0; (var) < (max); ++(var))
#define FORi(var, min, max) for (ul (var) = (min); (var) < (max); ++(var))
#define FORi_INV(var, min, max) for (ul (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

static ul y, m, d;

void solve(void) {
  if (y >= 2019 && m >= 5 && d >= 1) {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
}

int main(void) {
  char t;
  cin >> y >> t >> m >> t >> d;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
#define MV 1000
struct edge{int to,cost; };
vector <edge> G[MV];
int V,E;
ll d[MV+1];
bool bellmanford(int s){
	rep(i,V){
		d[i]=INFl;
	}
	d[s] = 0;
	int c = 0;
	bool upd = false;
	bool goalupd=false;//出発点から目的地までの経路での負の閉路の存在判定
	while(true){
		upd = false;
		goalupd = false;
		for(int i = 0;i < V;i++){
			for(int j = 0;j < G[i].size();j++){
				edge e = G[i][j];
				if(d[i] != INFl && d[e.to] > d[i] + e.cost){
					//printf("c:%d i:%d to:%d oldcost:%lld newcost:%lld\n",c,i,e.to,d[e.to],d[i] + e.cost);
					d[e.to] = d[i] + e.cost;
					upd = true;
					if(e.to==V-1) goalupd=true;
				}
			}
		}
		if(c>=V-1&& !upd) return false;
		if(c>=V-1&& goalupd) return true;
		if(c == 2*V-1) return false;
		c++;
	}
}
int main(){
	int N,M;
	int first=0;
	int a[2001],b[2001],c[2001];
	scan(V);scan(E);
	rep(i,E){
		scan(a[i]);scan(b[i]);scan(c[i]);
		edge e;
		e.to=b[i]-1;
		e.cost=-c[i];
		G[a[i]-1].push_back(e);
	}
	bool flag=bellmanford(first);
	if(flag) prin("inf");
	else{
		/*rep(i,V){
			prin(-d[i]);
		}*/
		prin(-d[V-1]);
	}
	return 0;
}


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

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	
	int n,d;
	int hani=0,ninzu=0;
	cin >> n;
	syc(n,1,20);
	cin >> d;
	syc(d,1,20);
	hani=d+d+1;
	ninzu=n/hani;
	if(n%hani != 0)ninzu++;
	cout << ninzu << endl;
	return 0;
}


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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }

  /* ユークリッドの互除法 */
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
  if (p == 0) {
    return 1;
  }
  if (p % 2 == 0) {
    int64_t t = __pow_mod(n, p / 2, mod);
    return (t * t) % mod;
  }
  return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
  int64_t res = __pow_mod(n, p, mod);
  if (res == 0) {
    res = mod;
  }
  return res;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C) {
    if(A==B){
        if (B==C){
            cout<<NO<<endl;
            return;
        }else{

            cout<<YES<<endl;
            return;
        }
    }else{
        if (B==C){
            cout<<YES<<endl;
            return;
        }else{
            if(A==C){

                cout<<YES<<endl;
                return;
            }else {
                cout << NO << endl;
                return ;
            }
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long A;
  std::cin >> A;
  long long B;
  std::cin >> B;
  long long C;
  std::cin >> C;
  solve(A, B, C);
  return 0;
}


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

using ull = unsigned long long int;
using ll = long long int;
using du = double;
using ld = long du;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vdu = vector<du>;
using vs = vector<string>;
using vc = vector<char>;
using si = set<int>;
using sll = set<ll>;
using sdu = set<du>;
using sld = set<ld>;
using pii = pair<int, int>;
using pll = pair<ll,ll>;
using pdu = pair<du,du>;
using pld = pair<ld,ld>;
using pis = pair<int,string>;

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define sp(x) setprecision(x)<<fixed
#define loop(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pi acos(-1)
#define meme(a,x) memset(a,x,sizeof(a))
#define fout() cout.flush()
//King's Move
vi f={0,0,1,-1};
vi g={-1,1,0,0};
//debugger

#ifdef KAIZER
#include "debug.h"
#else
#define debug(x...)
#endif
//debugger

//functions
bool check_pow(ll a)
{
    if((a&(a-1))==0) return true;
    else return false;
}
ld my_pow(ld a,int b)
{
    ld ans=1;
    for(int i=0;i<b;i++) ans*=a;
    return ans;
}
ll digits(ll a)
{
    string line=to_string(a);
    return line.size();
}
bool prime_check(ll a)
{
    bool flag=true;
    for(ll i=2;i<=sqrt(a);i++)
    {
        if(a%i==0) {flag=false; break;}
    }
    return flag;
}
bool comp(const pair<int,int> &a , pair<int,int> &b)
{
    if(a.ff!=b.ff) return a.ff>b.ff;
    else return a.ss<b.ss;
}
//functions

int main()
{
    FASTIO;
    int n;
    cin>>n;
    vector<bool> a(n);
    loop(i,n)
    {
        int x,y;
        cin>>x>>y;
        a[i]=(x==y);
    }
    bool flag=false;
    for(int i=0;i<n-2;i++)
    {
        if(a[i]&&a[i+1]&&a[i+2]) {flag=true;break;}
    }
    if(flag) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;

int main(){
  FASTIO
  int m, d;
  cin>>m>>d;
  set<string>s;
  for(int i=2;i<=9;i++){
    for(int j=2;j<=9;j++){
      if(i*j<=m && 10*i+j<=d){
        string t=to_string(i*10+j);
        s.insert(t);
      }
    }
  }
  cout<<s.size()<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		do {
			double a = sc.nextDouble();
			double b = sc.nextDouble();
			double c = sc.nextDouble();
			double d = sc.nextDouble();
			double e = sc.nextDouble();
			double f = sc.nextDouble();
			double x = 1 / (a * e - b * d) * (e * c - b * f);
			double y = 1 / (a * e - b * d) * (-d * c + a * f);
			x = (double) ((int) Math.round(1000 * x)) / 1000;
			y = (double) ((int) Math.round(1000 * y)) / 1000;
			System.out.printf("%.3f %.3f\n", x, y);
		} while (sc.hasNextInt());
		
	}

}

Measured memory_bytes: 20652
#include <stdio.h>

int main(){
	int H,W,N,total=0,time=0;
	scanf("%d%d%d",&H,&W,&N);
	
	while(1){
		if(N<=total){
			break;
		} else {
			if(H>=W){
				total = total + H;
				W--;
			} else {
				total = total + W;
				H--;
			}
			time++;
		}
	}
	printf("%d",time);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int n, a[100];
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      a[(i-1)*10 + (j-1)] = i * j;
    }
  }
  cin >> n; 
  bool flag = false;
  for(int i = 0; i<10; i++){
    for(int j=0; j<10; j++){
      if (a[i*10 + j] == n){
        flag = true;
        break;
      }
    }
  }
  cout << (flag?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
IN = sys.stdin.readlines()

ans = min(a) + min(b)

for i in range(M):
    x, y, c = map(int, IN[i].split())
    x -= 1; y -= 1
    ans = min(ans, a[x] + b[y] - c)

print(ans)


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

ll calc(ll h) {
    ll res = 1;
    ll tmp = 1;
    while (h / 2) {
        h /= 2;
        tmp *= 2;
        res += tmp;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll h;
    cin >> h;
    cout << calc(h) << endl;
    
    return 0;
}



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

using namespace std;

int main(void)
{
	int K,T;
	vector<int> a;

	cin>>K>>T;

	for(int i = 0;i < T;i++)
	{
		int temp;
		cin>>temp;

		a.push_back(temp);
	}
	
	sort(a.begin(),a.end(),greater<int>());
	int pre_index = -1;
	for(int i = 0;;i++)
	{
		if(T == 1)
			break;
		if(i != pre_index && a[i] > 0)
		{
			K--;
			a[i] = a[i]-1;
			pre_index = i;

			if(a[i] == 0)
				T--;
			i = -1;
		}
	}

	if(a[0] == 0)
		cout<<a[0]<<endl;
	else
		cout<<a[0]-1<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 998244353;
const int N = 1e6+205;
ll a[N];
int n; 
ll f(int x){
	ll ret = 0;
	for(int i=1;i<=n;i++){
		ret+=(a[i]-x)*(a[i]-x);
	}
	return ret;
}
void solve(){
	cin>>n; 
	for(int i=1;i<=n;i++)cin>>a[i];
	int st = 0;
	int en = 1e6;
	while(st<=en){
		int mid1 = st+(en-st)/3;
		int mid2 = en-(en-st)/3;
		if(f(mid1)>f(mid2)){
			st = mid1+1;
		}
		else{
			en = mid2-1;
		}
	}
	cout<<f(st)<<endl;
	
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


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

int X, Y;
bool able = false;

int main(){
  cin >> X >> Y;
  
  for(int i = 0; i <= X; i++){
    if(2*i + 4*(X-i) == Y){ able = true; break; }
  }
  
  if(able) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int t[50001];

int main( void )
{
	int i, j, n, m, c[20];
	
	scanf( "%d", &n );
	scanf( "%d", &m );
	
	for ( i = 0; i < m; i++ ) {
		scanf( "%d", &c[i] );
	}
	
	for ( i = 0; i < 50001; i++ )
		t[i] = -1;
	t[0] = 0;
	
	for ( i = 0; i < m; i++ )
		for ( j = c[i]; j <= n; j++ )
			if ( t[j] > (t[j - c[i]] + 1) || t[j] == -1 )
				t[j] = t[j - c[i]] + 1;
				
	printf( "%d\n", t[n] );
	
	return 0;
}

Measured memory_bytes: 788
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
 
void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];
    char[][] ss;
    foreach (_; 0..H) ss ~= readln.chomp.to!(char[]);
 
    auto DP = new int[][][](2, H, W);
    foreach (ref dp1; DP) foreach (ref dp2; dp1) dp2[] = -1;
    int solve(int c, int i, int j) {
        auto x = c == 0 && ss[i][j] == '#' ? 1 : 0;
        if (i == H-1 && j == W-1) return x;
        if (DP[c][i][j] == -1) {
            auto cc = ss[i][j] == '.' ? 0 : 1;
            DP[c][i][j] = min(
                i == H-1 ? 10001 : solve(cc, i+1, j) + x,
                j == W-1 ? 10001 : solve(cc, i, j+1) + x
            );
        }
        return DP[c][i][j];
    }
    writeln(solve(0, 0, 0));
}

Measured memory_bytes: 380
fun main() = Thread(null, ::abc170d, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc170d() {
    readLine()!!
    val aList = readLine()!!.split(' ').map { it.toInt() }

    val max = aList.max()!!.toInt()
    val isValid = BooleanArray(max + 1)
    aList.forEach { isValid[it] = true }

    for (a in aList.distinct().sorted()) {
        if (!isValid[a]) continue
        var num = 2
        while (num <= max / a) isValid[(num++ * a)] = false
    }

    aList.groupBy { it }.filter { it.value.size >= 2 }
        .forEach { (t, _) -> isValid[t] = false }

    val answer = isValid.count { it }

    println(answer)
}


Measured memory_bytes: 111028
import itertools

if __name__ == '__main__':
    n, m = map(int, input().split())

    xyzs = []
    for _ in range(n):
        xyzs.append(list(map(int, input().split())))

    ans = 0
    signs = itertools.product([-1, 1], [-1, 1], [-1, 1])
    for sign in signs:
        sign_sums = []
        for xyz in xyzs:
            sign_sums.append(sum([v * s for v, s in zip(xyz, sign)]))

        sign_sums = sorted(sign_sums, reverse=True)
        ans = max(ans, sum(sign_sums[:m]))

    print(ans)


Measured memory_bytes: 3388
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>
#include <time.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];

	while (A.size() > 1){
		sort(A.begin(), A.end(), less<long long>());
		for (vector<long long>::iterator itr = A.begin() + 1; itr != A.end();){
			*itr %= A[0];
			if (*itr == 0)
				itr = A.erase(itr);
			else
				++itr;
		}
	}
	cout << A[0] << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
char s[200],t[200];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s%s",s,t);
	for(int i=n;i>=0;i--){
		bool flag=true;
		for(int j=0;j<i;j++){
			if(s[n-i+j]!=t[j]) flag=false;
		}
		if(flag){
			printf("%d\n",n+n-i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
const int N=1e5+10;
int n,h[N],dp[N];
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)scanf("%d",&h[i]);
	dp[2]=abs(h[2]-h[1]);
	for(register int i=3;i<=n;i++)
		dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n][3];
	
	for(int i=0; i<n; i++)
	for(int j=0; j<3; j++)
	cin>>arr[i][j];
	
	for(int i=1; i<n; i++)
	{
	 arr[i][0] = max(arr[i-1][1] + arr[i][0],arr[i-1][2] + arr[i][0]);
	 arr[i][1] = max(arr[i-1][0] + arr[i][1],arr[i-1][2] + arr[i][1]);
	 arr[i][2] = max(arr[i-1][1] + arr[i][2],arr[i-1][0] + arr[i][2]);
	}
	
	cout<<max({arr[n-1][0],arr[n-1][1],arr[n-1][2]});
	
	return 0;
}

Measured memory_bytes: 4796
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

ll func(ll x){
    return ((x+1)*x/2);
}

int main()
{
    ll N;
    cin >> N;
    if(N == 1 || N == 2){
        cout << N << endl;
        return 0;
    }
    int ans=0;
    REP(i,N){
        if(func(i) >= N){
            ans = i;
            break;
        }
    }
    int sub = func(ans) - N;
    for(int i=1; i<= ans; i++){
        if(i == sub)continue;
        cout << i << endl;
    }
}

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

int main() {
    ios_base::sync_with_stdio(false);
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<pair<bool, int>>> a(n);
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        a[l].push_back({true, i});
        a[r].push_back({false, i});
    }
    vector<vector<int>> prec(n, vector<int>(n));
    for (int l = 0; l < n; l++) {
        vector<int> was(m, false);
        int cnt = 0;
        for (int i = l; i < n; i++) {
            for (auto pr: a[i]) {
                int tr = pr.second;
                if (pr.first) {
                    was[tr] = true;
                } else if (was[tr]) {
                    cnt++;
                }
            }
            prec[l][i] = cnt;
        }
    }
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << prec[l][r] << endl;
    }
}

Measured memory_bytes: 6768
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("funroll-loops")
#pragma GCC optimize("fomg-optimize")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7840
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  int sum = 0, mn = 0;
  rep(i, n) {
    if(s[i] == '(') sum++;
    else sum--;
    chmin(mn, sum);
  }
  cout << string(-mn, '(') + s + string(sum-mn, ')') << endk;
  return 0;
}


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

int main() {

	ll n, k; cin >> n >> k;
	vector<ll> c(n);
	for (ll i = 0; i < n; ++i) {
		cin >> c[i];
	}
	ll a = n - 1;
	ll b = k - 1;
	cout << (a + b - 1) / b << endl;
	return 0;
}

Measured memory_bytes: 3968