akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    ll t[n],a[n];
    rep(i,n) cin>>t[i]>>a[i];

    ll nt=t[0];
    ll na=a[0];
    for(int i=1;i<n;i++){

        if(t[i]<nt || a[i]<na){
            ll x=(nt+t[i]-1)/t[i];
            ll y=(na+a[i]-1)/a[i];
            x=max(x,y);
            nt=x*t[i];
            na=x*a[i];
        }
        else{
            nt=t[i];
            na=a[i];
        }

        //cout<<nt<<" "<<na<<endl;
    }

    cout<<nt+na<<endl;
}


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

int main() {
    int count = 0;
    string s1, s2;
    cin >> s1;
    cin >> s2;
    for (int i=0; i<s1.size(); i++) {
        if (s1[i] != s2[i]) {
            count ++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3916
#include <iostream>

using namespace std;

int main()
{
	long long x, k, d;
	cin >> x >> k >> d;
	if (x < 0)
		x = -x;
	long long moves_required = x / d;
	if (k <= moves_required)
		cout << (x - k * d) << endl;
	else
		if ((k - moves_required) % 2 == 0)
			cout << (x - moves_required * d) << endl;
		else
			cout << (d - (x - moves_required * d)) << endl;
	return 0;
}

Measured memory_bytes: 3624
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {

var inputs = chunk.toString().trim().split('\n').map(Number);

    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i] === 0) {
            break;
        }
        console.log('Case ' + (i + 1) + ': ' + inputs[i]);
    }

});

Measured memory_bytes: 20712
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(m)]

for i in a:
    result = []
    for j in zip(*b):
        result.append(sum([a * b for (a,b) in zip(i, j)]))
    print(*result)



Measured memory_bytes: 6584
#include <iostream>
using namespace std;
int main()
{
	int A[3][3], N, b[10];
	int x = 0;
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			cin >> A[i][j];
	cin >> N;
	for (int k = 0; k < N; k++)
		cin >> b[k];
	for (int k = 0; k < N; k++)
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				if (b[k] == A[i][j])
					A[i][j] = 0;
	for (int i = 0; i < 3; i++)
		if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0)
			x += 1;
	for (int j = 0; j < 3; j++)
		if (A[0][j] == 0 && A[1][j] == 0 && A[2][j] == 0)
			x += 1;
	if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) {
		x += 1;
	}
	if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0) {
		x += 1;
	}
	if (x == 0)
		cout << "No" << "\n";
	else
		cout << "Yes" << "\n";
}

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

int main() {
	int n;
	cin >> n;
	int num = 0;
	int fish = -1;
	for (int i = 0; i < n; ++i) {
		int a, v;
		cin >> a >> v;
		if (fish < v) {
			num = a;
			fish = v;
		}
		else if (fish == v && num > a) {
			num = a;
		}
	}
	cout << num << ' ' << fish << endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>

using namespace std;

uint32_t gcb_2(uint32_t a, uint32_t b);
uint32_t gcb_3(uint32_t a, uint32_t b, uint32_t c);

int main()
{
    uint32_t kk;
    uint32_t sum = 0;
    cin >> kk;

    for(int i = 1; i <= kk; i++){
        for(int k = 1; k <= kk; k++){
            for(int l = 1; l <= kk; l++){
                sum += gcb_3(i, k, l);
            }
        }
    }

    cout << sum << endl;
    return 0;
}

uint32_t gcb_2(uint32_t a, uint32_t b)
{
    uint32_t temp = 0;
    temp = a % b;
    if(temp == 0)
        return b;
    return gcb_2(b, temp);
};

uint32_t gcb_3(uint32_t a, uint32_t b, uint32_t c)
{
    uint32_t temp = 0;
    temp = gcb_2(a, b);
    return gcb_2(temp, c);
};

Measured memory_bytes: 3636
x, n = map(int, input().split())
import numpy as np
P  = list(map(int, input().split()))
if len(P)==0:
    print(x)
else:
    a = x
    b = x
    for i in range(len(P)+1):
        if a not in P:
            print(a)
            break
        if b not in P:
            print(b)
            break
        a -= 1
        b += 1

Measured memory_bytes: 27160
#include<bits/stdc++.h>
using namespace std;
char str[100100];
bool vis[26];
char a[100100];
int solve(int x,int n){
	int res=0,cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(str[i]!='a'+x)
			cnt++;
		a[i]=str[i];
	}
	if(!cnt) return 0;
	while(n--){
		cnt=0;
		for(int i=1;i<=n;i++){
			if(a[i]=='a'+x||a[i+1]=='a'+x)
				a[i]='a'+x;
			else
				cnt++;
		}
		res++;
		if(!cnt)
			return res;
	}
	return res;
}
int main(){
//	freopen("A.in","r",stdin);
	int n;
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=1;i<=n;i++)
		vis[str[i]-'a']=1;
	int ans=n-1;
	for(int i=0;i<26;i++)
	{
		if(vis[i])
			ans=min(ans,solve(i,n));
	}
	printf("%d\n",ans);
	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 ALL(x) (x).begin(), (x).end()

const int INF = 1e9;

typedef int Weight;
typedef int Flow;

struct Edge {
  int src, dest, rev;
  Flow cap;
  Weight cost;
  bool operator < (const Edge &rhs) const {
    return cost > rhs.cost;
  }
  Edge(int s, int d) : src(s), dest(d) { ; }
  Edge(int s, int d, Weight c) : src(s), dest(d), cost(c) { ; }
  Edge(int s, int d, int r, Flow cp, Weight cst) : src(s), dest(d), rev(r), cap(cp), cost(cst) { ; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

vector<Weight> dijkstra(const Graph &g, int s) {
  int n = g.size();
  vector<Weight> d(n, INF);
  d[s] = 0;
  priority_queue<Edge> que;
  que.push(Edge(-1, s, 0));
  while(!que.empty()) {
    Edge e = que.top();
    que.pop();
    if(d[e.dest] < e.cost) continue;
    for(Edge f : g[e.dest]) {
      if(d[f.dest] > e.cost + f.cost) {
        d[f.dest] = e.cost + f.cost;
        que.push(Edge(f.src, f.dest, d[f.dest]));
      }
    }
  }
  return d;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M), c(M);
  REP(i,M) {
    cin >> a[i] >> b[i] >> c[i]; --a[i]; --b[i];
  }

  Graph g(N);
  REP(i,M) {
    g[a[i]].push_back(Edge(a[i], b[i], c[i]));
    g[b[i]].push_back(Edge(b[i], a[i], c[i]));
  }
  vector<vector<int>> d(N);
  REP(i,N) d[i] = dijkstra(g, i);

  int res = 0;
  REP(i,M) {
    bool flag = false;
    REP(j,N) if(d[j][a[i]] + c[i] == d[j][b[i]]) flag = true;
    if(!flag) ++res;
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 384
import sys
sys.stdin.readline

def main():
    H, W, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    X = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
    Y = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
    XY = list(zip(X, Y))
    S = {}
    for a, b in AB:
        for x, y in XY:
            k = (a+x, b+y)
            S.setdefault(k, 0)
            S[k] += 1
    ans = [0] * 10
    for (x, y), v in S.items():
        if 1 < x < H and 1 < y < W:
            ans[v] += 1
    ans[0] = (H-2)*(W-2)-sum(ans[1:])
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

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

string s;
int a[1000];

string solve(int i) {
  if (i == s.length()) {
    for (int j = 97; j < 123; j++) {
      if (a[j] == 0) {
        string sub = "";
        sub += char(j);
        return sub;
      }
    }
    return "-1";
  } else if (a[s[i]] == 1) {
    for (int j = s[i] + 1; j < 123; j++) {
      if (a[j] == 0) {
        a[j] = 1;
        string sub = "";
        sub += char(j);
        return sub;
      }
    }
    return "-1";
  } else {
    a[s[i]] = 1;
    string sub = solve(i + 1);
    if (sub == "-1") {
      a[s[i]] = 0;
      for (int j = s[i] + 1; j < 123; j++) {
        if (a[j] == 0) {
          a[j] = 1;
          string sub = "";
          sub += char(j);
          return sub;
        }
      }
      return "-1";
    }
    return s[i] + sub;
  }
}

int main() {

  cin >> s;

  string res = solve(0);  

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
  	int	N;
  	int	a;
  	int	num;
  	int	i;
  
  	num = scanf("%d", &N);
  	if (num != 1)
      	return (0);
  
  	for (i=0; i<N; i++)
    {
      	num = scanf("%d", &a);
      	if (num != 1)
          	return (0);
        if (a % 2 == 1)
            continue ;
      	else if (a % 6 == 0)
      	{
      	    continue ;
      	}
      	else if (a % 10 == 0)
      	{
      	    continue ;
      	}
      	else if (a % 6 != 0)
      	{
          	printf("DENIED");
          	return (0);
      	}
      	else if (a % 10 != 0)
      	{
          	printf("DENIED");
          	return (0);
      	}
    }
  	printf("APPROVED");
  	return (0);
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

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

	cin >> N;
	vector<vector<int>>edge(N);
	vector<pair<int, int>>e;
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		L--, R--;
		e.push_back({ min(L,R),max(L,R) });
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>depth(N, MOD);
	Calculate_Depth(edge, depth, 0);
	cin >> M;
	vector<set<pair<int, int>>>box(M);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		L--, R--;
		while (depth[L] > depth[R]) {
			long long int nx = -1;
			for (auto j : edge[L]) {
				if (depth[j] < depth[L])nx = j;
			}
			box[i].insert({ min(nx,L),max(nx,L) });
			L = nx;
		}
		while (depth[R] > depth[L]) {
			long long int nx = -1;
			for (auto j : edge[R]) {
				if (depth[j] < depth[R])nx = j;
			}
			box[i].insert({ min(nx,R),max(nx,R) });
			R = nx;
		}
		while (L != R) {
			long long int nx = -1;
			for (auto j : edge[L]) {
				if (depth[j] < depth[L])nx = j;
			}
			box[i].insert({ min(nx,L),max(nx,L) });
			L = nx;
			nx = -1;
			for (auto j : edge[R]) {
				if (depth[j] < depth[R])nx = j;
			}
			box[i].insert({ min(nx,R),max(nx,R) });
			R = nx;
		}
	}
	vector<vector<long long int>>dp(N, vector<long long int>(1 << M));
	dp[0][0] = 1;
	for (int i = 0; i < N - 1; i++) {
		int add = 0;
		for (int k = 0; k < M; k++) {
			if (box[k].find(e[i]) != box[k].end())add |= 1 << k;
		}
		for (int j = 0; j < 1 << M; j++) {
			dp[i + 1][j] += dp[i][j];
		//	dp[i + 1][j] %= MOD;
			dp[i + 1][j | add] += dp[i][j];
		//	dp[i + 1][j | add] %= MOD;
		}
	}
	cout << dp.back().back() << endl;
	return 0;
}

Measured memory_bytes: 418304
import java.util.Scanner;


public class Main {

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

		int N = sc.nextInt();

		int[] K = new int[N];
		for(int i = 0 ; i < N ; i++){
			K[i] = sc.nextInt();
		}

		sc.close();

		int[] A = new int[9];

		for(int i = 0 ; i < N ; i++){
			if(K[i]<=399){
				A[0]++;
			}
			else if(K[i]>=400 && K[i] <= 799){
				A[1]++;
			}
			else if(K[i]>=800 && K[i] <= 1199){
				A[2]++;
			}
			else if(K[i]>=1200 && K[i] <= 1599){
				A[3]++;
			}
			else if(K[i]>=1600 && K[i] <= 1999){
				A[4]++;
			}
			else if(K[i]>=2000 && K[i] <= 2399){
				A[5]++;
			}
			else if(K[i]>=2400 && K[i] <= 2799){
				A[6]++;
			}
			else if(K[i]>=2800 && K[i] <= 3199){
				A[7]++;
			}
			else{
				A[8]++;
			}
		}

		int ans = 0;
		for(int i = 0 ; i < 8 ; i++){
			if(A[i]!=0){
				ans++;
			}
		}
		if(ans != 0){
			System.out.println(Math.min(8, ans) + " " + (ans + A[8]));
		}
		else{
			System.out.println(1 + " " + (ans + A[8]));
		}
	}
}


Measured memory_bytes: 21844
// https://beta.atcoder.jp/contests/abc045
// status:

#define SUBMIT
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(9999999999
)");
#endif
    string S;
    stream >> S;

    ll ans = 0;
    ll len = S.length();
    for (int bit = 0; bit < (1 << (len - 1)); ++bit) {
        int prev_i = 0;
        ll sum = 0;
        for (int i = 0; i < len - 1; ++i) {
            if (bit & (1 << i)) {
                sum += atoll(S.substr(prev_i, i + 1 - prev_i).c_str());
                prev_i = i + 1;
            }
        }

        sum += atoll(S.substr(prev_i, len - prev_i).c_str());
        ans += sum;
    }

    cout << ans << endl;
    return 0;
}

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

int main(void)
{
    int a, b;
    int i;
    int now = 1;
    int num = 0;

    cin >> a;
    cin >> b;

    while(now < b){
        now = now + a - 1;
        num++;
    }

    cout << num;

    return 0;

}

Measured memory_bytes: 256
a, op, b = input().split()
while op != '?':
    a, b = int(a), int(b)
    if op == '+': a += b
    if op == '-': a -= b
    if op == '*': a *= b
    if op == '/': a = int(a / b)
    print(a)
    a, op, b = input().split()


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,type=-1;
	scanf("%d",&n);
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			if(4*i+7*j==n)
			{
				type=0;
			}
		}
	}
	if(type==-1)
	{
		printf("No");
	}else
	{
		printf("Yes");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#include <utility>
#include <iomanip>
#include <sstream> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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; }
const ll MOD = 1000000007;
const ll INF = 1LL << 60;


ll dat[100100] = { 0 };


int main()
{
	ll n, q;
	cin >> n;
	vector<ll> a(n);

	rep(i, n) {
		cin >> a[i];
		dat[a[i]]++;
	}

	cin >> q;
	vector<ll> b(q), c(q);
	rep(i, q) {
		cin >> b[i] >> c[i];
	}

	ll sum = 0;
	rep(j, 100100) {
		sum += dat[j] * j;
	}

	rep(i, q) {
		sum -= (dat[b[i]] * b[i]);
		sum += dat[b[i]] * c[i];

		cout << sum << endl;
 
		dat[c[i]] += dat[b[i]];
		dat[b[i]] = 0;

	}
	
}




Measured memory_bytes: 6368
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

std::map<long long, int> prime_factor(long long n) {
  std::map<long long, int> res;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) {
    res[n] = 1;
  }
  return res;
}

int main() {
  const int mod = 1000000000 + 7;
  int n;
  cin >> n;

  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    auto m = prime_factor(i);
    for (auto it = m.begin(); it != m.end(); it++) {
      mp[it->first] += it->second;
    }
  }

  long long ans = 1;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans *= (it->second + 1);
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (((ll)1<<31)-1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0;
using namespace std;
int n;
double a,b,c,d,e,f;
pair<double,double> func(double A,double B,double C,double D,double E,double F){
    double ans1=(C*E-B*F)/(A*E-B*D),ans2=(C*D-A*F)/(B*D-A*E);
    if(C*E==B*F)ans1=0;
    if(C*D==A*F)ans2=0;
    return {ans1,ans2};
}
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a>>b>>c>>d>>e>>f;
        double A=2*(-a+c),B=2*(-b+d),C=a*a+b*b-c*c-d*d;
        double D=2*(-a+e),E=2*(-b+f),F=a*a+b*b-e*e-f*f;
        pair<double,double> p=func(A,B,-C,D,E,-F);
        double ans1=p.first,ans2=p.second;
        printf("%.3lf %.3lf %.3lf\n",ans1,ans2,hypot(a-ans1,b-ans2));
    }
    ggr;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 2e5 + 5;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	string s, t;
	cin >> s >> t;
	int res = 0;
	for (int i = 0; i < SZ(s); i++) {
		if (s[i] != t[i])
			res++;
	}
	cout << res << endl;
	return 0;
}


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

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
/*-------------------------------------------------*/
template <typename T>
vector<vector<T> > rot(const vector<vector<T> > &grid, int angle) {
  int h = grid.size(), w = grid.front().size();
  if (angle == 45) {
    vector<vector<T> > rotated_grid(h + w - 1, vector<T>(h + w - 1, ' '));
    REP(i, h) REP(j, w) rotated_grid[i + j][j - i + h - 1] = grid[i][j];
    return rotated_grid;
  } else if (angle == 90) {
    vector<vector<T> > rotated_grid(w, vector<T>(h));
    REP(i, h) REP(j, w) rotated_grid[w - 1 - j][i] = grid[i][j];
    return rotated_grid;
  } else {
    assert(false);
  }
}

// http://phyllo-algo.hatenablog.com/entry/2018/10/29/000320
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int h, w; cin >> h >> w;
  vector<vector<char> > s(h, vector<char>(w)); REP(i, h) REP(j, w) cin >> s[i][j];
  // マンハッタン距離を考えるため45度回転させる
  s = rot(s, 45);

  int ans = 0;
  REP(_, 4) {
    h = s.size(); w = s.front().size();
    vector<vector<int> > row(h, vector<int>(w + 1, 0));
    REP(i, h) {
      REP(j, w) row[i][j + 1] = row[i][j] + (s[i][j] == '#' ? 1 : 0);
    }
    REP(i, h) REP(j, w) if (s[i][j] == '#') {
      FOR(k, j + 1, w) if (s[i][k] == '#') {
        int r = i - (k - j);
        if (r >= 0) ans += row[r][k] - row[r][j];
      }
    }
    s = rot(s, 90);
  }
  cout << ans << '\n';
  return 0;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
          	var input_B = Console.ReadLine()
                .ToCharArray().Select(i => int.Parse(i.ToString())).ToArray();
            var isMMYY_M0 = Regex.IsMatch(input_B[1].ToString(), @"[1-9]+$");
            var isMMYY_M1 = Regex.IsMatch(input_B[1].ToString(), @"[0-2]+$");
            var isYYMM_M0 = Regex.IsMatch(input_B[3].ToString(), @"[1-9]+$");
            var isYYMM_M1 = Regex.IsMatch(input_B[3].ToString(), @"[0-2]+$");

            var isMMYY = false;
            var isYYMM = false;
            if ((input_B[0] == 0 && isMMYY_M0) || (input_B[0] == 1 && isMMYY_M1))
                isMMYY = true;

            if ((input_B[2] == 0 && isYYMM_M0) || (input_B[2] == 1 && isYYMM_M1))
                isYYMM = true;

            if(isYYMM && isMMYY)
            {
                Console.WriteLine("AMBIGUOUS");
            }
            else if (isYYMM)
            {
                Console.WriteLine("YYMM");
            }
            else if (isMMYY)
            {
                Console.WriteLine("MMYY");
            }
            else
            {
                Console.WriteLine("NA");
            }
        }
    }
}


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

int main(){
   ll n;cin>>n;
   int arr[n];
   int count=0;
   for(int i=0;i<n;i++){
      cin>>arr[i];
      if((i+1)%2!=0 && arr[i]%2!=0){
         count++;
      }
   }
   cout<<count<<endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
int main(){
	int n, i, ac=0, wa=0, tle=0, re=0;
    scanf("%d",&n); 

    char s[n][3];
 
 
    for(i=0;i<n;i++){
    	scanf("%s", &s[i]);
       if(s[i][0]=='A'){
         ac++;
       }
       else if(s[i][0]=='W'){
         wa++;
       }
       else if(s[i][0]=='T'){
         tle++;
       }
       else{
         re++;
       }
    }
    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d\n",re);
return 0;
}

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

int main() {
    int N;
    cin >> N;
    int A;
    int max = 0;
    int max_i = -1;
    int second = 0;
    for (int i = 0; i < N; i ++) {
        cin >> A;
        if (A > max) {
            second = max;
            max = A;
            max_i = i;
        } else if (A > second) {
            second = A;
        }
    }
    for (int i = 0; i < N; i++) {
        if (max_i == i ) {
            cout << second << endl;
            continue;
        }
        cout << max << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
const long long MOD=1e9+7;
int main(){
  string s;
  cin>>s;
  int a[11]={};
  long long ans=0;
  int n=s.size();
  for(int i=0;i<n;++i){
    a[i]=s[i]-'0';
  }

  for(int bit=0;bit<1<<(n-1);++bit){
    long long k=bit,num=a[0];
    for(int i=0;i<n-1;++i){
        if(k&(1<<i)){
            ans+=num;
            num=a[i+1];
        }else{
            num*=10;
            num+=a[i+1];
        }
    }
    ans+=num;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let H: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let W: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    fn iceil(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    let ans = iceil(N, std::cmp::max(H, W));

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
	ll a,b,c,d,K;cin>>a>>b>>c>>d>>K;
    ll d1=K%60,c1=K/60;
    c-=c1;d-=d1;
    ll sum=(c-a)*60+d-b;
    cout<<sum<<endl;
}



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

int main()
{
    long long H;
    scanf("%lld", &H);
    long long W;
    scanf("%lld", &W);
    string S;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            std::cin >> S; 
            if (S == "snuke"){
                cout << char('A' + j) << 1 + i << endl;
                break;
            }
        }
        if (S == "snuke")
            break;
    }
    return 0;
}


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

int main()
{
	long long N, K;
	scanf("%lld %lld", &N, &K);
	if (K % 2 == 1) printf("%lld\n", (N / K) * (N / K) * (N / K));
	else printf("%lld\n", (N / K) * (N / K) * (N / K) + ((N + K / 2) / K) * ((N + K / 2) / K) * ((N + K / 2) / K));
	fflush(stdout);
	return 0;
}

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

int main(void)
{
	int n, b, f, r, v;
	int room[4][3][10];
	int i = 0;
	char bar[21] = { "####################" };

	for (int i = 0;i < 4;i++) {
		for (int j = 0;j < 3;j++) {
			for (int k = 0;k < 10;k++) {
				room[i][j][k] = 0;
			}
		}
	}

	cin >> n;
	for (int i = 0;i < n;i++) {
		do {
			cin >> b >> f >> r >> v;
			room[b - 1][f - 1][r - 1] += v;
			if (room[b - 1][f - 1][r - 1] > 9) room[b - 1][f - 1][r - 1] = 9;
			else if (room[b - 1][f - 1][r - 1] < 0) room[b - 1][f - 1][r - 1] = 0;
		} while (b < 0 || b > 4 || f < 0 || f > 3 || r < 0 || r > 10);
	}
	for (int i = 0;i < 4;i++) {
		for (int j = 0;j < 3;j++) {
			for (int k = 0;k < 10;k++) {
				printf(" %d", room[i][j][k]);
			}
			printf("\n");
		}
		if (i < 3) printf("%s\n", bar);
	}

	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll xgcd (ll a,ll b){
    if(b){
        return xgcd(b,a%b) + a/b*b*2;
    }else{
        return 0;
    }
}
ll gcd (ll a,ll b){
    return b ? gcd(b,a%b) : a;
}
main(){
    ll N,X;
    cin >> N >> X;
    ll ans = N;
    ll a = N-X, b = X;
    ans += xgcd(a,b) - gcd(a,b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;
using ll = long long int;

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    
    cout << (n+1-a)*(n+1-b);
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int n = s.length;
        sc.close();
        boolean flag = true;
        int[] ans = new int[n];

        int Lorigin = 0;
        int Rorigin = 0;
        for(int i=0;i<n;i++){
            if(s[i]=='R' && !flag){
               Rorigin = i;
               flag = true;
               ans[Lorigin-1] += (i-Lorigin)/2;
               ans[Lorigin] += (i-Lorigin+1)/2;
            }else if(s[i]=='L' && flag){
                Lorigin = i;
                flag = false;
                ans[i-1]+=(i-Rorigin+1)/2;
                ans[i]+=(i-Rorigin)/2;
            }

        }
        ans[Lorigin-1] += (n-Lorigin)/2;
        ans[Lorigin] += (n-Lorigin+1)/2;
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<n;i++){
            out.printf("%d ", ans[i]);
        }
        out.flush();

    }

}

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

const int N = (int)1e5 + 10;
const double eps = 1e-8;

template <typename T> inline T gcd(T a, T b) { a = abs(a), b = abs(b); while ( b ) { a %= b; swap(a, b); } return a; }
vector <pair <int, int> > adj[N + 7];
int color[N + 7];

void dfs(int u, int p, int c) {
	color[u] = c;
	for ( int i = 0; i < adj[u].size(); ++i ) {
		int v = adj[u][i].first;
		int w = adj[u][i].second;
		if ( v != p ) {
			if ( w % 2 == 0  ) {
				dfs(v, u, color[u]);
			} else {
				dfs(v, u, !color[u]);
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for ( int i = 0; i < n - 1; ++i ) {
		int u, v, w;
		cin >> u >> v >> w;
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	}
	color[0] = 1;
	dfs(1, 0, 1);
	for ( int i = 1; i <= n; ++i ) {
		cout << color[i] << "\n";
	}
    return 0;
}


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

int main(){
  int i, Tlen, Plen;
  char *T, *P;

  T = (char* )malloc(sizeof(char) * 1000000);
  P = (char* )malloc(sizeof(char) * 10000);

  scanf("%s%s", T, P);

  Tlen = strlen(T);
  Plen = strlen(P);

  for(i=0; i<Tlen; i++){
    if(strncmp(&T[i], P, Plen) == 0) printf("%d\n", i);
  }

  return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int dx[] = { 1,-1,0,0 };
const int dy[] = { 0,0,-1,1 };
const int maxn = 22;
const int maxv = maxn*maxn;
int G[maxv][maxv], h,w; char B[maxn][maxn];

int ij2v(const int i, const int j)
{ return i*w+j; }
void v2ij(const int v, int& i, int& j)
{ i = v/w; j = v%w; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> h >> w) {
        const int n = h*w;
        FOR(i,0,n) FOR(j,0,n)
            G[i][j] = i==j ? 0 : inf;
        FOR(i,0,h) FOR(j,0,w)
            cin >> B[i][j];
        FOR(i,0,h) FOR(j,0,w) if (B[i][j] == '.') {
            FOR(d,0,4) {
                const int x = i+dx[d];
                const int y = j+dy[d];
                if (0 <= x && x < h && 0 <= y && y < w) {
                    if (B[x][y] == '.') {
                        const int u = ij2v(i,j);
                        const int v = ij2v(x,y);
                        G[u][v] = 1;
                    }
                }
            }
        }
        FOR(k,0,n) FOR(i,0,n) FOR(j,0,n)
            G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
        int ans = 0;
        FOR(i,0,n) FOR(j,0,n) if (i != j) {
            int x,y; v2ij(i,x,y);
            int X,Y; v2ij(j,X,Y);
            if (B[x][y] == '.' && B[X][Y] == '.')
                ans = max(ans, G[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	
	string s;
	cin >> s;
	cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll A,B;
    cin >>A>>B;
    if(B%A == 0){
        cout<<A+B<<endl;
    }else{
        cout<<B-A<<endl;
    }
    
   


    return 0;
    

}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vunique(v) unique(v.begin(), v.end());

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

	int N, A;
	cin >> N >> A;
	cout << pow(N, 2) - A << endl;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    int l = a+b;
    int r = c+d;

    string ans;
    if(l == r){
        ans = "Balanced";
    }
    else if(l > r){
        ans = "Left";
    }
    else{
        ans = "Right";
    }

    cout << ans << endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

long long dp[101][2000000];

int main() {
    long long N, W;
    cin >> N >> W;

    for (int i = 0; i < 101; i++) {
        for (long long j = 0; j <= N * 1000; j++) {
            dp[i][j] = W + 1;
        }
    }
    dp[0][0] = 0;

    long long w, v;
    for (int i = 1; i <= N; i++) {
        cin >> w >> v;

        for (long long j = 0; j <= N * 1000; j++) {
            chmin(dp[i][j], dp[i - 1][j]);
            if (j - v >= 0 && dp[i - 1][j - v] + w <= W) {
                chmin(dp[i][j], dp[i - 1][j - v] + w);

            }
        }
    }

    for (long long v = N * 1000; v >= 0; v--) {
        if (dp[N][v] <= W) {
            cout << v << endl;
            break;
        }
    }
}

Measured memory_bytes: 287744
#include<cstdio>
#include<algorithm>
using namespace std;

int n,chain[10000];

int fig(int b){
	int a = b-1,c = b+1,color,res = 0;
	if(a>=0){//b == 0のバターンを弾く
		int s = 1;
		color = chain[a];
		while(a>=0 && color==chain[a])a--,s++;
		while(c<n && color==chain[c])c++,s++;
		if(s>=4)while(a>=0 && c<n){
			int t = 0;
			color = chain[a];
			while(a>=0 && color==chain[a])a--,t++;
			while(c<n && color==chain[c])c++,t++;
			if(t>=4) s+=t;
			else break;
		}
		else s = 0;
		res = s;
		a = b-1;c = b+1;
	}
	if(c<n&&(a<0||chain[a]!=chain[c])){//b == n-1のパターンとchain[a] == chain[c]のパターンを弾く
		int s = 1;
		color = chain[c];
		while(a>=0 && color==chain[a])a--,s++;
		while(c<n && color==chain[c])c++,s++;
		if(s>=4)while(a>=0 && c<n){
			int t = 0;
			color = chain[a];
			while(a>=0 && color==chain[a])a--,t++;
			while(c<n && color==chain[c])c++,t++;
			if(t>=4) s+=t;
			else break;
		}
		else s = 0;
		res = max(res,s);
	}
	return res;
}

int main(){
	while(scanf("%d",&n),n){
		int del = 0;
		for(int i = 0; i < n; i++){
			scanf("%d",chain+i);
		}
		
		for(int i = 0; i < n; i++) del = max(del,fig(i));
		printf("%d\n",n-del);
	}
	return 0;
}

Measured memory_bytes: 0
#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++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
	string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;
    if(u==s) a--;
    else b--;
    cout << a << " " << b << endl;
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L

#define INF 0x3f3f3f3f
//const int N = 2e5 + 5;

 
//int vis[N];
bool sortcol(const vector<int>& v1,
	const vector<int>& v2) {
	return v1[0] < v2[0];
}

int32_t  main() {

	IOS;
  
	int N, K;

	cin >> N >> K;
	vector<int> k(N+1);
	for (int i = 0; i < K; i++) {
		int tmp;
		cin >> tmp;

		for (int j = 0; j < tmp; j++) {
			int tmp2;
			cin >> tmp2;
			k[tmp2]++;
		}

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

		if (k[i] == 0) {
			cnt++;
		}

	}
	cout << cnt << endl;
}

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

long long int N, a[200202], b[200202];

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i){
        scanf("%lld", a + i);
        b[i] = a[i];
    }
    sort(b, b + N);
    for(int i = 0; i < N; ++i){
        printf("%lld\n", (a[i] < b[N / 2]) ? b[N / 2] : b[N / 2 - 1]);
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int inf = 1e9;

int32_t main(){
	cin.tie(0); ios::sync_with_stdio(0);
	
	int n, k;
	cin >> n >> k;
	vector<int> a(n+k, inf), dp(n+k, inf);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= k; j++){
			dp[i+j] = min(dp[i+j], dp[i] + abs(a[i] - a[i+j]));
		}
	}
	
	cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(int argc, char *argv[])
{
	long long int N,a,i;
	scanf("%lld",&N);
	a=sqrt(N);
	for(i=a;i>=0;i--){
		if(N%i==0){
			 printf("%lld\n",i+(N/i)-2);
			 break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n_plus, n_zero, n_minus, n_cards = map(int, input().split())

if n_cards <= n_plus:
  print(min(n_plus, n_cards))
elif n_cards <= (n_plus + n_zero):
  print(n_plus)
else:
  print(n_plus - (n_cards - n_plus - n_zero))

Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  double ans = 1;
  for(int i = 1; i < x/2; i++){
    for(int j = 2; j < x/2; j++){
      if(pow(i, j) <= x)
        ans = max(pow(i, j), ans);
      else
        break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
#define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

const int mod = 1e9 + 7;
const int N = 4e5 + 5;

int a[N];

bool is(int n) {
	if (n < 4) {
		return 1;
	}
	if (n % 2 == 0) {
		return 0;
	}
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) {
			return 0;
		}
	}
	return 1;
}
 
inline void solve() {
 int a, b;
 cin >> a >> b;
 set < int > v;
 for (int i = 1; i * i <= a; ++i) {
 	// cout << i << ' ' << '\n';
 	if (a % i == 0) {
 		if (b % i == 0) {
 			v.insert(i);
 		}
 		int x = a / i, y = b / i;
 		// cout << x << ' ' << y << '\n';
 		if (a % x == 0 && b % x == 0)
 			v.insert(x);
 		if (a % y == 0 && b % y == 0)
 			v.insert(y);
 		
 	}
 }
 // for (auto i : v) {
 // 	cout << i << ' ';
 // }
 // E;
 int ans = 0;
 for (auto i : v) {
 	ans += is(i);
 }
 cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t; while(t--)
  solve();
  return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
static const int inf = 1 << 30;

int main(void) {
  string s;
  cin >> s;
  int price = 700;
  REP(i, 3) {
    if (s[i] == 'o') {
      price += 100;
    }
  }
  cout << price << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define  pi acos(-1.0)
#define  eps 1e-6
#define  fi first
#define  se second
#define  rtl   rt<<1
#define  rtr   rt<<1|1
#define  bug         printf("******\n")
#define  mem(a,b)    memset(a,b,sizeof(a))
#define  name2str(x) #x
#define  fuck(x)     cout<<#x" = "<<x<<endl
#define  f(a)        a*a
#define  sf(n)       scanf("%d", &n)
#define  sff(a,b)    scanf("%d %d", &a, &b)
#define  sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define  sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define  pf          printf
#define  FRE(i,a,b)  for(i = a; i <= b; i++)
#define  FREE(i,a,b) for(i = a; i >= b; i--)
#define  FRL(i,a,b)  for(i = a; i < b; i++)+
#define  FRLL(i,a,b) for(i = a; i > b; i--)
#define  FIN         freopen("data.txt","r",stdin)
#define  gcd(a,b)    __gcd(a,b)
#define  lowbit(x)   x&-x
using namespace std;
typedef long long  LL;
typedef unsigned long long ULL;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
int k;
LL sum ( LL x ) {
    int ret = 0;
    while ( x ) {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}
int main()  {
    sf ( k );
    LL ans = 1, p = 1;
    while ( k-- ) {
        printf ( "%lld\n", ans );
        LL ans1 = ans + p, ans2 = ans + p * 10;
        if ( ans1 * sum ( ans2 ) <= ans2 * sum ( ans1 ) ) ans = ans1;
        else ans = ans2,p*=10;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#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) cout << #x << " : " << x << " ------------ " << endl;
using namespace std;
int main()
{
    string letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int n;
    while (cin >> n, n) {
        vector<int> k(n);
        rep(i, n) cin >> k[i];
        string s;
        cin >> s;
        auto kIt = k.begin();
        auto lbIt = letters.cbegin();
        rep(i, s.length()) {
            auto lIt = lbIt + letters.find(s[i]);
            rep(j, *kIt) {
                if (lIt == lbIt) lIt = letters.end();
                --lIt;
            }
            cout << *lIt;
            if (++kIt == k.end()) kIt = k.begin();
        }
        cout << endl;
    }
    
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3196
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>











ll n,m,k;



void solve()
{
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i*m+j*n==2*i*j+k)
			{
				cout<<"Yes\n";
				return;
			}
		}
	}
	cout<<"No\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
        int a[10][10],n,d,i,j,k,l=0,p=0,ans;
        int s[10];
        scanf("%d%d",&n,&d);
        for(i=0;i<n;i++){
            for(j=0;j<d;j++){
                scanf("%d",&a[i][j]);
            }
        }
       for(i=0;i<n-1;i++){
            for(k=i+1;k<n;k++){
                ans=0;
                for(j=0;j<d;j++){
                    ans=ans+((a[i][j]-a[k][j])*(a[i][j]-a[k][j]));
                }
                s[p]=ans,p++;
            }
       }
       for(i=0;i<p;i++){
            ans=sqrt(s[i]);
            if(ans*ans==s[i]){
                l++;
            }
       }
       printf("%d",l);
       return 0;
}


Measured memory_bytes: 2128