akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

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

    vector<vector<int>> num(110,vector<int>(110));

    int x,y,a;
    for(int i=0;i<N;i++){
        cin >> x >> y >> a;
        switch(a){
            case 1:
                for(int l=0;l<H;l++){
                    for(int i=0;i<x;i++){
                        num[l][i]=1;
                    }
                }
                break;
            case 2:
                for(int l=0;l<H;l++){
                    for(int i=x;i<W;i++){
                        num[l][i]=1;
                    }
                }
                break;
            case 3:
                for(int l=0;l<W;l++){
                    for(int i=0;i<y;i++){
                        num[i][l]=1;
                    }
                }
                break;
            case 4:
                for(int l=0;l<W;l++){
                    for(int i=y;i<H;i++){
                        num[i][l]=1;
                    }
                }
                break;
        }
    }
    int sum=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(num[i][j]==0) sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
//#include<numeric>
#include<algorithm>
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;

typedef long long ll;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main()
{
    int k;
    ll sum=0;
    cin>>k;
    rep(a,k)
    {
        rep(b,k)
        {
            rep(c,k)
            {
                int tmp=gcd(a,b);
                sum+=gcd(tmp,c);
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 3636
N = int(input())
S = input()
a = ""
b = []

List = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]

for i in range(len(S)):
    a = S[i]
    c = List.index(a)
    c = c + N
    if 25 < c:
        c = c - 26
    b.append(List[c])

for i in range(len(b)):
    print(b[i], end ='')     

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

int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if (x-r>=0&&y-r>=0&&x+r<=W&&y+r<=H){
    cout<<"Yes"<<endl;
    } else {
    cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3120
// 2020-07-17 08:24:47
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll lcm = c / __gcd(c, d) * d;
  ll ans = 0;
  ans += b / c;
  ans += b / d;
  ans -= b / lcm;
  ans -= (a-1) / c;
  ans -= (a-1) / d;
  ans += (a-1) / lcm;
  ans = b - a + 1 - ans;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
const int INF = 2e9;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,d; cin >> n >> d;
  d *= d;
  int cnt = 0;
  REP(i,n){
    ll x,y; cin >> x >> y;
    if(x*x+y*y<=d) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3656
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  int h,w,a,b;
  cin >> h >> w >> a >> b;

  rep(i,h){
    rep(j,w){
      if(j<a && i<b){
        cout << "0";
      }
      else if(i>=b && j>=a){
        cout << "0";
      }
      else{
        cout << "1";
      }
    }
    cout << endl;
  }
}

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

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

	int a[100000];
	for (int i = 1; i <= N; i++)
	{
		cin >> a[i];
	}

	int l = 1;
	int count = 1;
	while (a[l] != 2)
	{
		l = a[l];
		count++;
		if (count > N)
		{
			count = -1;
			break;
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 768
// 2011/03/24 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

	for(int i=0; i<n; i++){
		string str;
		cin >> str;

		for(int j=0; j<7; j++)
			for(int k=j+1; k<8; k++)
				if(str[j]<str[k]){
					char tmp = str[j];
					str[j] = str[k];
					str[k] = tmp;
				}

		int max = 0;
		for(int j=0; j<8; j++)
			max = max*10+(str[j]-'0');

		int min = 0;
		for(int j=7; j>=0; j--)
			min = min*10+(str[j]-'0');

		cout << max-min << endl;
	}

	return 0;
}

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

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

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

int main(void){
 
    int r;
    
    scanf("%d", &r);
    
    if (r<1200) {
        printf("ABC");
    } else if (r<2800) {
        printf("ARC");
    } else {
        printf("AGC");
    }
    
    return 0;
}



Measured memory_bytes: 1728
S= input()
T= input()
s=len(S)
t=len(T)
a=0
for i in range(s-t+1):
    cnt=0
    for j in range(t):
        if S[i+j]==T[j]:
            cnt=cnt+1
    if cnt>a:
        a=cnt
print(t-a)

Measured memory_bytes: 8944
#include<bits/stdc++.h>
using namespace std;
using LL=int64_t;
const int INF=0x3f3f3f3f;
const int maxn=1e6+5;
bool book[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    LL a,b,ans=0;
    cin>>a>>b;
    if(b<=9) ans=a*10+b;
    else if(b<=99) ans=a*100+b;
    else ans=a*1000+b;
    memset(book,false,sizeof(book));
    for(int i=0;i*i<maxn;i++) book[i*i]=true;
    if(book[ans]!=true) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
#include <string.h>

int main(){
  int i,j,m,h,l;
  char s[201]={},temp[201]={};

  while(1){
    memset(s,'\0',201);
    scanf("%s\n",s);
    if(s[0]=='-'){
      break;
    }
    l = strlen(s);
    scanf("%d\n", &m);
    memset(temp,'\0',201);
    for(i=0;i<m;i++){
      scanf("%d",&h);
      for(j=0;j<h;j++){
        temp[j] = s[j];
      }
      for(j=h;j<l;j++){
        s[j-h] = s[j];
      }
      for(j=0;j<h;j++){
        s[l-h+j] = temp[j];
      }
    }
    printf("%s\n",s);
  }


  return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

struct edge{
    int to,dist;
};

struct state{
    int node,dist;
    bool operator<(const state& r)const{
        return dist>r.dist;
    }
};

int main(){
    int N;
    cin >> N;
    vec<string> W(N);
    map<string,int> m;
    int id = 1;
    for(int i=0;i<N;i++){
        cin >> W[i];
        int n = W[i].size();
        for(int j=0;j<n;j++){
            string S = W[i].substr(n-j-1,j+1);
            if(!m.count(S)) m[S] = id++;
        }
    }
    const int s = 0,t = id;
    vvec<edge> g(id+1);
    m[""] = t;
    for(auto& x:m){
        string S = x.first;
        if(S=="") continue;
        int n = S.size();
        for(int i=0;i<N;i++){
            if(W[i].size()<n){
                if(S.substr(0,W[i].size())==W[i]){
                    string T = S.substr(W[i].size(),n-W[i].size());
                    g[x.second].push_back({m[T],0});
                }
            }
            else if(S==W[i].substr(0,n)){
                string T = W[i].substr(n,W[i].size()-n);
                g[x.second].push_back({m[T],(int) T.size()});
            }
        }
    }
    int inf = 1e9;
    vec<int> dp(id+1,inf);
    dp[s] = 0;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++){
        string S = W[i],T = W[j];
        if(S.size()>T.size()) swap(S,T);
        if(S!=T.substr(0,S.size())) continue;
        string R = T.substr(S.size(),T.size()-S.size());
        g[s].push_back({m[R],(int) T.size()});
    }
    priority_queue<state> Q;
    Q.push({s,0});
    while(!Q.empty()){
        state now = Q.top(); Q.pop();
        if(dp[now.node]<now.dist) continue;
        for(auto& e:g[now.node]){
            int c = now.dist+e.dist;
            if(dp[e.to]>c){
                dp[e.to] = c;
                Q.push({e.to,c});
            }
        }
    }
    cout << (dp[t]!=inf? dp[t]:0) << endl;
}


Measured memory_bytes: 4064
#include<iostream>
using namespace std;
long ans,a,b;
main()
{
	cin>>a>>b;
	if(((b-a+1)/2+(a%2&&b%2))%2)ans=1;
	for(int i=1;i<60;i++)
	{
		long cnt=0,I=1LL<<i;
		if(a&I)
		{
			cnt+=I-a%I;
		}
		if(b&I)
		{
			cnt+=b%I+1;
		}
		if(cnt%2)ans|=1LL<<i;
	}
	cout<<ans<<endl;
}

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

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

ll gcd(ll a, ll b) {
    if(a < b) swap(a, b);
    if (b==0) return a;
    return gcd(b, a%b);
}

int main() {
    int x;
    cin >> x;
    cout << 3 * x * x << endl;

}



Measured memory_bytes: 256
N_POINTS = int(input())
POINTS = [[0, 0, 0]]
for _ in range(N_POINTS):
    POINTS.append([int(value) for value in input().split(' ')])


def is_accessible_point(point1, point2):
    distance = abs(point1[1] - point2[1]) + abs(point1[2] - point2[2])
    time = point2[0] - point1[0]
    if distance > time or (time - distance) % 2 != 0:
        return False
    return True


def is_accessible_points(n_points, points):
    for i in range(n_points):
        if is_accessible_point(points[i], points[i + 1]):
            continue
        else:
            return False
    return True


if is_accessible_points(N_POINTS, POINTS):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 21052
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var _ = LnInts();
        var N = _[0];
        var K = _[1];
        var ps = LnInts();
        var Dice = new double[N];
        for (int i = 0; i < N; i++)
        {
            Dice[i] = (double)SumAtoB(1, ps[i]) / (double)ps[i];
        }
        var Sums = new double[N+1];
        for (int i = 0; i < N; i++)
        {
            Sums[i+1] = Sums[i] + Dice[i];
        }
        var left = 0;var right = K;
        var max = 0D;
        while (right <= N)
        {
            var sum = Sums[right] - Sums[left];
            max = sum > max ? sum : max;
            right++;
            left++;
        }
        print(max);
    }

public static long SumAtoB(long a,long b){var length = b - a + 1;return (a + b) * (length / 2) + (length % 2 == 1 ? (a + b) / 2 : 0);}
public static long PowLite(long n, long p, int mod = (int)1e9 + 7){long ans = 1;long now = n;for (; p > 0; p >>= 1){if ((p & 1) == 1){ans *= now;ans %= mod;}now *= now;now %= mod;}return ans;}
public static void print(object obj) { Console.WriteLine(obj); }
public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable{var a = new List<T>(array).ToArray();var res = new List<T[]>();res.Add(new List<T>(a).ToArray());var n = a.Length;var next = true;while (next){next = false;int i;for (i = n - 2; i >= 0; i--){if (a[i].CompareTo(a[i + 1]) < 0) break;}if (i < 0) break;var j = n;do{j--;} while (a[i].CompareTo(a[j]) > 0);if (a[i].CompareTo(a[j]) < 0){var tmp = a[i];a[i] = a[j];a[j] = tmp;Array.Reverse(a, i + 1, n - i - 1);res.Add(new List<T>(a).ToArray());next = true;}}return res;}}


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

using namespace std;

using i32 = int32_t;
using u32 = uint32_t;
using f32 = float;
using f64 = double;
using i64 = int64_t; 
using u64 = uint64_t; 

#define SELECTER(_1, _2, _3, _4, _5, _6, _7, _8, SELECT, ...) SELECT

#define _FC1(func, type, _1)      func(type, _1) 
#define _FC2(func, type, _1, ...) func(type, _1); _FC1(func, type, __VA_ARGS__)
#define _FC3(func, type, _1, ...) func(type, _1); _FC2(func, type, __VA_ARGS__) 
#define _FC4(func, type, _1, ...) func(type, _1); _FC3(func, type, __VA_ARGS__)
#define _FC5(func, type, _1, ...) func(type, _1); _FC4(func, type, __VA_ARGS__)
#define _FC6(func, type, _1, ...) func(type, _1); _FC5(func, type, __VA_ARGS__)
#define _FC7(func, type, _1, ...) func(type, _1); _FC6(func, type, __VA_ARGS__)
#define _FC8(func, type, _1, ...) func(type, _1); _FC7(func, type, __VA_ARGS__)

#define _FCN(func, type, ...) SELECTER(__VA_ARGS__, _FC8, _FC7, _FC6, _FC5, _FC4, _FC3, _FC2, _FC1)(func, type, __VA_ARGS__)

constexpr const char *type2fmt(const char *fmt) {
  if(strcmp(fmt, "i32") == 0) return "%d";
  if(strcmp(fmt, "u32") == 0) return "%u";
  if(strcmp(fmt, "f32") == 0) return "%f";
  if(strcmp(fmt, "f64") == 0) return "%lf";
  if(strcmp(fmt, "i64") == 0) return "%lld";
  if(strcmp(fmt, "u64") == 0) return "%llu";
  return "";
}

#define _R(type, _1) type _1; { type _t; scanf(type2fmt(#type), &_t); _1 = _t; }
#define _P(type, _1) { const type _t = (_1); printf(type2fmt(#type), _t); putchar('\n'); }

#define RI(...)   _FCN(_R, i32, __VA_ARGS__)
#define RUI(...)  _FCN(_R, u32, __VA_ARGS__)
#define RF(...)   _FCN(_R, f32, __VA_ARGS__)
#define RD(...)   _FCN(_R, f64, __VA_ARGS__)
#define RLL(...)  _FCN(_R, i64, __VA_ARGS__)
#define RULL(...) _FCN(_R, u64, __VA_ARGS__)

#define PI(...)   _FCN(_P, i32, __VA_ARGS__)
#define PUI(...)  _FCN(_P, u32, __VA_ARGS__)
#define PF(...)   _FCN(_P, f32, __VA_ARGS__)
#define PD(...)   _FCN(_P, f64, __VA_ARGS__)
#define PLL(...)  _FCN(_P, i64, __VA_ARGS__)
#define PULL(...) _FCN(_P, u64, __VA_ARGS__)

#define REP(n) for (int _i = 0; _i < n; _i++)

const u64 mod = 1000000007;

int main() {
  RULL(A, B, C);
  PULL(A * B / 2);
}


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

using namespace std;

int n;
vector<int> bounce;

bool IsReachable() {
    int current = 0;
    for ( int i=0; i<n; ++i ) {
	if ( current < 10*i ) return false;
	current = max( current, 10*i + bounce[i] );
	if ( current >= 10*n ) return true;
    }
    return false;
}

int main() {

    cin >> n;
    bounce.resize( n );
    for ( int i=0; i<n; ++i ) cin >> bounce[i];
    if ( !IsReachable() ) {
	cout << "no" << endl;
	return 0;
    }
    
    reverse( bounce.begin(), bounce.end() );
    if ( !IsReachable() ) cout << "no" << endl;
    else cout << "yes" << endl;
    
    return 0;
}



Measured memory_bytes: 3904
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100010
typedef pair<int,int> pii;
 
class Union_Find{
public:
    int par[MAX],rank[MAX],W[MAX];
    Union_Find(int N){
	for(int i = 0 ; i < N ; i++){
	    par[i] = i;
	    rank[i] = W[i] = 0;
	}
    }
 
    pii find(int x){
	if(par[x] == x) return pii(x,0);
	pii p = find(par[x]);
	par[x] = p.first;
	W[x] = (p.second += W[x]);
	return p;
    }
 
    void unite(int x,int y,int w){
	pii nx = find(x), ny = find(y);
	x = nx.first; y = ny.first;
	if(x == y) return;
	w -= nx.second-ny.second;
	if(rank[x] < rank[y]){
	    par[x] = y; W[x] = w;
	}else{
	    par[y] = x; W[y] = -w;
	    if(rank[x] == rank[y]){
		rank[x]++;
	    }
	}
    }
 
    bool same(int x,int y){
	return (find(x).first == find(y).first);
    }
 
    int diff(int a,int b){
	return W[a]-W[b];
    }
};
 
int main(){
    int N,M,a,b,c;
    while(cin >> N >> M,N){
	Union_Find uf(N);
	for(int i = 0 ; i < M ; i++){
	    char ch;
	    cin >> ch >> a >> b;
	    a--; b--;
	    if(ch == '!'){
		cin >> c;
		uf.unite(a,b,c);
	    }else{
		if(uf.same(a,b)){
		    cout << uf.diff(a,b) << endl;
		}else{
		    puts("UNKNOWN");
		}
	    }
	}
    }
    return 0;
}

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

int main(void)
{
  int A[3][3];
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> A[i][j];
    }
  }

  int N;
  cin >> N;

  int B[3][3];
  int b;
  for (int k = 0; k < N; k++)
  {
    cin >> b;
    for (int i = 0; i < 3; i++)
    {
      for (int j = 0; j < 3; j++)
      {
        if (A[i][j] == b)
        {
          B[i][j] = 1;
        }
      }
    }
  }

  string result = "No";
  if ((B[0][0] == 1 && B[0][1] == 1 && B[0][2] == 1) ||
      (B[1][0] == 1 && B[1][1] == 1 && B[1][2] == 1) ||
      (B[2][0] == 1 && B[2][1] == 1 && B[2][2] == 1) ||
      (B[0][0] == 1 && B[1][0] == 1 && B[2][0] == 1) ||
      (B[0][1] == 1 && B[1][1] == 1 && B[2][1] == 1) ||
      (B[0][2] == 1 && B[1][2] == 1 && B[2][2] == 1) ||
      (B[0][0] == 1 && B[1][1] == 1 && B[2][2] == 1) ||
      (B[0][2] == 1 && B[1][1] == 1 && B[2][0] == 1))
  {
    result = "Yes";
  }
  cout << result << endl;
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var strs = str.Split(' ');
            var N = int.Parse(strs[0]);
            var K = int.Parse(strs[1]);

            var h = new int[N];
            for (int i = 0; i < N; i++)
            {
                h[i] = int.Parse(Console.ReadLine());
            }

            Array.Sort(h);

            var diff = new List<int>();
            for (int i = 0; i + K - 1 < N; i++)
            {
                diff.Add(h[i + K - 1] - h[i]);
            }

            Console.WriteLine(diff.Min());
        }
    }
}


Measured memory_bytes: 18012
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
     
    while(x!=NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        }else{
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NULL) {
        root = z;
    } else {
        if(z->key < y->key) {
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;
    
    scanf("%d", &n);
    
    for (i=0; i<n; i++) {
        cin >> com;
        if(com == "insert") {
            scanf("%d", &x);
            insert(x);
        }else if(com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 26700
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC74(void);
void ABC75(void);
void ABC76(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC78();
}

void ABC78(){
    int x,y,z,c=0;
    cin>>x>>y>>z;
    for(int i=0;x>0;i++){
        if(i==0){
            x-=y+2*z;
            if(x>=0)c++;
        }
        x-=y+z;
        if(x>=0)c++;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
import numpy as np


n, d = [int(i) for i in input().split()]

X = []
for i in range(n):
	X.append([int(i) for i in input().split()])

X = np.array(X)
ans = 0
dis = []
for i in range(n):
	for k in range(i+1, n):
		dis = np.sqrt(np.power(X[i]-X[k],2).sum()) 
		if int(dis)==dis:
			ans += 1

print(ans)

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

int n, a[100010][3], dp[100010][3];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n; ++i)
		for(int j=0; j<3; ++j)
			cin >> a[i][j];
	for(int i=1; i<=n; ++i)
		for(int j=0; j<3; ++j)
			dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + a[i][j];
	cout << max({dp[n][0], dp[n][1], dp[n][2]}) << "\n";
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,n;
    cin>>x>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<110;i++){
        if(binary_search(a,a+n,x-i)==0){
            cout<<x-i<<endl;
            break;
        }
        if(binary_search(a,a+n,x+i)==0){
            cout<<x+i<<endl;
            break;
        }
    }
    return 0;
}


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

bool a[100005];
int p[100005];

int main() {
    int n, m;
    cin >> n >> m;

    int ac = 0, pena = 0;
    rep(i, m) {
        int x;
        string s;
        cin >> x >> s;
        if (a[x]) continue;

        if (s == "AC")
            a[x] = 1, ac++, pena += p[x];
        else
            p[x]++;
    }

    cout << ac << ' ' << pena << endl;
    return 0;
}


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

int N;
string S;

void solve()
{
	int ans = 1;
	int st = 0;
	for(int i=1;i<N;++i){
		if(S[i] == S[st]) continue;
		st = i;
		ans++;
	}
	cout << ans << "\n";
}

int main()
{
	cin >> N >> S;
	solve();
	return 0;
}

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

#include <iostream>
#include <vector>
// #include <map>
// #include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

uint h;
uint w;
vector<uint> h_vec; // cumulate
vector<uint> w_vec; // cumulate
vector<uint> h_count;
vector<uint> w_count;

void print() {
	for (uint i = 0; i < h_count.size() and i < w_count.size(); i++) {
		cout << i << " : h " << h_count[i] << " w " << w_count[i] << endl;
	}
}

int main() {
	while (1) {
		uint val;
		uint sum;
		// input
		cin >> h >> w;
		if (h == 0 and w == 0) {
			break;
		}
		h_vec.clear();
		sum = 0;
		for (uint i = 0; i < h; i++) {
			cin >> val;
			sum += val;
			h_vec.push_back(sum);	
		}
		h_count.resize(sum + 1);
		for (auto& v : h_count) {
			v = 0;
		}
		w_vec.clear();
		sum = 0;
		for (uint i = 0; i < w; i++) {
			cin >> val;
			sum += val;
			w_vec.push_back(sum);
		}
		w_count.resize(sum + 1);
		for (auto& v : w_count) {
			v = 0;
		}
		// make count
		for (auto v : h_vec) {
			h_count[v]++;
		}
		for (uint bef = 0; bef < h_vec.size(); bef++) {
			for (uint aft = bef + 1; aft < h_vec.size(); aft++) {
				val = h_vec[aft] - h_vec[bef];
				h_count[val]++;
			}
		}
		for (auto v : w_vec) {
			w_count[v]++;
		}
		for (uint bef = 0; bef < w_vec.size(); bef++) {
			for (uint aft = bef + 1; aft < w_vec.size(); aft++) {
				val = w_vec[aft] - w_vec[bef];
				w_count[val]++;
			}
		}
		// print();
		// count up
		uint count = 0;
		for (uint num = 0; num < h_count.size() and num < w_count.size(); num++) {
			count += h_count[num] * w_count[num];
		}
		cout << count << endl;
	}


	//std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}

Measured memory_bytes: 7272
<?php
$input = explode(' ', trim(fgets(STDIN)));
$n = $input[0];
$m = $input[1];
$matrix = [];
$vector = [];
for ($i=0; $i < $n; $i++) {
  $tmp = explode(' ', trim(fgets(STDIN)));
  foreach ($tmp as $value) {
    $matrix[$i][] = $value;
  }
}
for ($i=0; $i < $m; $i++) {
  $vector[$i] = trim(fgets(STDIN));
}
for ($i=0; $i < $n; $i++) {
  $answer = 0;
  for ($j=0; $j < $m; $j++) {
    $answer += $matrix[$i][$j] * $vector[$j];
  }
  echo $answer."\n";
}

Measured memory_bytes: 17268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=0; i--)
#define INF 100000000
#define ll long long

int h, w, n;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };
char field[31][31];

void drop(char f[][31]) {
	REP(i, 1, h) {
		REP(j, 0, w) {
			if (f[i][j] != '.') {
				int ny = i;
				while (ny > 0) {
					if (f[ny - 1][j] == '.') {
						swap(f[ny - 1][j], f[ny][j]);
					}
					else break;

					ny--;
				}
			}
		}
	}
}

bool delite(char f[][31]) {
	bool del[31][31] = {};

	REP(i, 0, h) {
		REP(j, 0, w) {
			char now = f[i][j];
			if (now == '.') continue;

			REP(k, 0, 4) {
				int ny = i + dy[k];
				int nx = j + dx[k];
				int cnt = 1;
				bool flag = false;

				do {
					if (ny < 0 || nx < 0 || ny >= h || nx >= w) break;
					if (now == f[ny][nx]) {
						cnt++;
						if (cnt >= n) {
							flag = true;
						}
					}
					else break;

					ny += dy[k];
					nx += dx[k];
				} while (1);

				if (!flag) continue;

				int yy = i;
				int xx = j;
				REP(l, 0, cnt) {
					del[yy][xx] = true;
					yy += dy[k];
					xx += dx[k];
				}
			}
		}
	}

	bool del_flag = false;
	REP(i, 0, h) {
		REP(j, 0, w) {
			if (del[i][j]) {
				f[i][j] = '.';
				del_flag = true;
			}
		}
	}

	return del_flag;
}

int main() {
	cin >> h >> w >> n;
	RREP(i, 0, h) {
		REP(j, 0, w) {
			cin >> field[i][j];
		}
	}

	REP(i, 0, h) {
		REP(j, 0, w) {
			if (j + 1 < w && field[i][j] != field[i][j + 1]) {
				swap(field[i][j], field[i][j + 1]);

				char check[31][31];
				REP(k, 0, h) {
					REP(l, 0, w) {
						check[k][l] = field[k][l];
					}
				}
				do {
					drop(check);
				} while (delite(check));

				bool join_flag = true;
				REP(k, 0, h) {
					REP(l, 0, w) {
						if (check[k][l] != '.') join_flag = false;
					}
				}
				if (join_flag) {
					cout << "YES" << endl;
					return 0;
				}

				swap(field[i][j], field[i][j + 1]);
			}
		}
	}

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

Measured memory_bytes: 3112
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
  
	int n;
	cin >> n;
	set<int> a;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		a.insert(x);
	}
	int m;
	cin >> m;
	for(int i = 0; i < m; i++){
		int x;
		cin >> x;
		if(a.count(x))a.erase(x);
		else a.insert(x);
	}
	for(auto i:a)cout << i << '\n';
    return 0;
}



Measured memory_bytes: 21956
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    a = [stdin.readline().rstrip() for _ in range(n)]
    b = [stdin.readline().rstrip() for _ in range(m)]

    for i in range(n-m+1):
        for j in range(n-m+1):
            flag = True
            for h in range(m):
                if a[i+h][j:j+m] != b[h]:
                    flag = False
                    break
            if flag == True:
                print("Yes")
                exit()
    print("No")






if __name__ == '__main__':
    solve()


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

typedef long long LL;

const int N = 50;
const int M = 250;

bool mat[N][N];

int n, m, s;
LL mod;

LL pow_mod(LL x, int p){
    LL s = 1;
    while(p){
        if(p & 1)   s = s * x % mod;
        x = x * x % mod;
        p >>= 1;
    }
    return s;
}

int query(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c, d);
    fflush(stdout);
    int x;
    scanf("%d", &x);
    return x;
}

void solve(int x1, int x2, int y1, int y2, int div, int s){
    if(s == 0 || x1 > x2 || y1 > y2)  return;
    int area = (x2 - x1 + 1) * (y2 - y1 + 1);
    if(area == s){
        for(int i=x1; i<=x2; i++){
            for(int j=y1; j<=y2; j++){
                mat[i][j] = 1;
            }
        }
        return;
    }
    if(div){
        int mid = x1 + x2 >> 1;
        int ans = query(x1, y1, mid, y2);
        solve(x1, mid, y1, y2, 1^div, ans);
        solve(mid+1, x2, y1, y2, 1^div, s - ans);
    } else {
        int mid = y1 + y2 >> 1;
        int ans = query(x1, y1, x2, mid);
        solve(x1, x2, y1, mid, 1^div, ans);
        solve(x1, x2, mid+1, y2, 1^div, s - ans);
    }
}

int main(){
    while(~scanf("%d %d %d %lld", &n, &m, &s, &mod)){
        memset(mat, 0, sizeof(mat));
        solve(0, n-1, 0, m-1, 1, s);
        LL ans = 0;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(mat[i][j]){
                    ans = (ans + pow_mod(2, i*m+j)) % mod;
                }
            }
        }
        printf("! %lld\n", ans);
        fflush(stdout);
    }
    return 0;
}


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

int trtable[] = {0, 1, 2, 3, 5, 7, 8, 9};

void solve(int n){
	if(n >= 8) solve(n / 8);
	cout << trtable[n % 8];
	return;
}

int main(){
	int n;
	while(cin >> n, n){ 
		solve(n);
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#! usr/bin/env python
# -*- coding: utf-8 -*-

from collections import deque
import heapq
import bisect
import math


def main():
    l = list(map(int, input().split()))

    if 1 in l and 9 in l and 7 in l and 4 in l:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
mod=2019
s=input()

d={}
temp=1
cnt=0
we=0
d[0]=1
for i in range(len(s)):
  we=(we+int(s[-1-i])*temp)%mod
  temp=temp*10%mod
  
  if we not in d:
    d[we]=1
  else:
    d[we]+=1

#print(d)
for i in d:
  cnt+=(d[i]*(d[i]-1))//2
print(cnt)

Measured memory_bytes: 68544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    string s;
    cin >> s;
    int count = 0;
    for(int i=1; i<s.size(); i++) {
        if(s[i] != s[i-1]) count++;
    }
    cout << count << endl;
}

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

int n;

void Process() {
  if (n % 1000)
    cout << 1000 - n % 1000;
  else
    cout << 0;
  cout << "\n";
}

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

  while (cin >> n) {
    Process();

    if (cin.eof())
      break;
  }

  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int A, B;
    cin >> A >> B;
    cout << max(0, A - B * 2) << endl;
}


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

int main(){

  int H, W; 
  while(cin >> H >> W, H|W){
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
        if((i+j)%2==0){
          cout << '#';
        }else{
          cout << '.';
        }
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3076
// // If you want something you've never had, you must be willing to do
// // something you've never done

// //  When the going gets tough,  the tough get going

// #pragma GCC optimize ("O3")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<int,int>, null_type,less<pair<int, int> >,rb_tree_tag,tree_order_statistics_node_update > pbds;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// #define int ll
ll power(ll a, ll b, ll mod) {
    ll res = 1;
    a %= mod;
    while(b) {
        if(b % 2) {
            res *= a;
            res %= mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}
const int INF = 2e9;

// ----------------------------------------------------------

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



signed main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0) {
        c -= b;
        if(c <= 0) {
            cout << "Yes\n";
            return 0;
        }
        a -= d;
        if(a <= 0) {
            cout << "No\n";
            return 0;
        }
    }
    if(a) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3644
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']

mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=inf

n,c=LI()
d=[defaultdict(int)for i in' '*3]
f=[]
for i in range(c):
    f+=[LI()]
for i in range(n):
    x=LI()
    for j in range(n):
        d[(i+j)%3][x[j]-1]+=1

for i in range(c):
    for j in range(c):
        for k in range(c):
            if len(set([i,j,k]))<3:
                continue
            tmp=0
        
            for col,cnt in d[0].items():
                tmp+=f[col][i]*cnt
            for col,cnt in d[1].items():
                tmp+=f[col][j]*cnt
            for col,cnt in d[2].items():
                tmp+=f[col][k]*cnt
            ans=min(ans,tmp)

print(ans)


Measured memory_bytes: 44888
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

signed main() 
{
    string s;
    cin>>s;
    int los = 0;
    for(auto i : s)los += (i=='x');
    if(los>7)cout<<"NO";
    else cout<<"YES";


        return 0;

}

//       g++ -g c.cpp ; ./a.exe

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

using namespace std;

int main() {
    int n; cin>>n;
    vector<int> an(n+1);
    for (int i=1;i<=n;i++) {
        int a; cin>>a;
        an[a] = i;
    }

    for (int i=1;i<=n;i++) {
        cout << an[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1152
A, B, K = [int(i) for i in input().split(" ")]

if A > B:
  N = A
else :
  N = B

yaku = []
for i in reversed(range(N + 1)):
  if i != 0:
    if (A % i == 0) and (B % i == 0):
      yaku.append(i)
  
print(yaku[K - 1])

Measured memory_bytes: 3060
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))


n=int(input())

for i in range(1,10):
    if n%i==0 and n/i < 10:
        print('Yes')
        exit()
print('No')



Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int a, b, c;
	int cnt = 0;
	scanf("%d %d %d", &a, &b, &c);
	int i;
	for(i = a; i <= b; i++)
	{
		if(c%i == 0)
		{
			cnt++;
		}
	}
        printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 596
import sys, math
sys.setrecursionlimit(10**6)

def b(n):
	i = 1
	while(True):
		if i * (i+1) == n*2:
			return i
		elif i * (i+1) > n*2:
			return 0
		else:
			i += 1

def main():
	n = int(input())
	ref = b(n)
	if ref == 0:
		print("No")
	else:
		print("Yes")
		s = [[] for i in range(ref+1)]
		k = 1
		for i in range(ref):
			for j in range(i+1,ref+1):
				s[i] += [k]
				s[j] += [k]
				k+=1
		print(ref + 1)
		for i in range(ref+1):
			print(str(ref) + " " + " ".join(map(str,s[i])))
	return

main()

Measured memory_bytes: 9076
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N = 1e5 + 7;
int dp[101][N];

int recur(int id, int n, int a[], int b[], int w, int tot_wt)
{
    if(tot_wt > w)
        return INT_MIN;
    
    if(id == n)
        return 0;
        
    if(dp[id][tot_wt] != -1)
        return dp[id][tot_wt];

    int ans = 0;

    ans = max(ans, b[id] + recur(id + 1, n, a, b, w, tot_wt + a[id]));
    ans = max(ans, recur(id + 1, n, a, b, w, tot_wt));

    return dp[id][tot_wt] = ans; 
}

int32_t main()
{
    int n, w;
    cin >> n >> w;
    int a[n], b[n];

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

    memset(dp, -1, sizeof(dp));

    cout << recur(0, n, a, b, w, 0) << "\n";
}

Measured memory_bytes: 79104
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main()
{
	int n, a, b, tmpb, tmpa = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (tmpa <= a) {
			tmpa = a;
			tmpb = b;
		}
	}
	cout << tmpa + tmpb << endl;
	return 0;
}

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

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

    int cnt0 = 0;
    for(int i=0; i<S.length(); i++){
        if(S[i] == '0') cnt0++;
    }

    int ans1 = cnt0*2;
    int ans2 = (S.length()-cnt0)*2;
    cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  string s, t;
  cin >> s >> t;
  bool flag = true;
  rep(i, s.size()) {
    if (s.at(i) != t.at(i)) {
      coNo;
      flag = false;
      break;
    }
  }
  if (flag) {
    coYes;
  }
}


  


Measured memory_bytes: 3580
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int n;

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

    double n, x;
    int t;
    cin >> n >> x >> t;
    cout << (int)ceil(n/x) * t << "\n";

    return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  string s;
  cin >> s;
  int a=0;
  for(int i=0;i<4;i++){
    if(s[i] == '+')
      a++;
    else
      a--;
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256