akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const double r = 1.0;
const double PI = acos(-1.0);
const double sq2 = sqrt(2.0);
const double dx[] = {0.0, 1.0, 0.0, 1.0};
const double dy[] = {0.0, 0.0, 1.0, 1.0};

struct Point {
    double x, y;
    Point() {}
    Point(double x, double y) : x(x), y(y) {}
};
struct Rect {
    double x, y, len; // ??????(x, y)??§?????????len?????£?????¢
    int ub;
    Rect() { ub = 0; }
    Rect(double x, double y, double len, int ub) : x(x), y(y), len(len), ub(ub) {}
};
bool operator<(const Rect &a, const Rect &b) {
    return a.ub < b.ub;
}
inline double Distance2(const Point &a, const Point &b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

int n;
vector<Point> p;

Rect MakeRect(double x, double y, double l, int &ans) {
    int num = 0, u_bound = 0;
    const double len = l * l * 0.5 + sq2 * l + 1.0;
    Point c(x + l * 0.5, y + l * 0.5);

    for (int i = 0; i < n; ++i) {
        double d = Distance2(c, p[i]);

        if (d <= 1.0)
            ++num;
        if (d <= len)
            ++u_bound;
    }

    ans = max(ans, num);

    return Rect(x, y, l, u_bound);
}

int Solve() {
    int ans = 1;
    priority_queue<Rect> que;

    que.push(MakeRect(0.0, 0.0, 10.0, ans));

    while (!que.empty()) {
        Rect now = que.top();
        que.pop();

        if (ans < now.ub) {
            double half = now.len * 0.5;

            for (int d = 0; d < 4; ++d) {
                Rect r = MakeRect(now.x + half * dx[d], now.y + half * dy[d], half, ans);
                if (ans < r.ub)
                    que.push(r);
            }
        }
    }

    return ans;
}

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

    while (cin >> n, n) {
        p.resize(n);
        for (int i = 0; i < n; ++i)
            cin >> p[i].x >> p[i].y;

        cout << Solve() << endl;
    }

    return 0;
}

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

int main(){
	int h,w;
	cin>>h>>w;
	rep(i,h){
		string s;
		cin>>s;
		cout<<s<<endl;
		cout<<s<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_num(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int a[101010], in[101010];
bool used[101010];

int main() {
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		a[i] = (i + a[i]) % n;
		in[a[i]]++;
	}
	int cnt = 0;
	queue<int> que;
	REP(i, n) {
		if (!in[i] && !used[i]) {
			used[i] = true;
			que.push(i);
		}
		while (que.size()) {
			int v = que.front();
			que.pop();
			cnt++;
			in[a[v]]--;
			if (!used[a[v]] && !in[a[v]]) {
				used[a[v]] = true;
				que.push(a[v]);
			}
		}
	}
	cout << n - cnt << endl;
}


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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

int main() {
	ll ans=0;
	int a,b;cin>>a>>b;
	pair<int,int> x[b];
	for(int i=0;i<b;i++){
		cin>>x[i].second>>x[i].first;
	}
	sort(x,x+b);
	int end=0;
	for(int i=0;i<b;i++){
		if(x[i].second>=end){
			ans++;
			end=x[i].first;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }

        static int N;
        static int[] A;
        static int[] anums;
        static double[,,] dp;
        static void Main(string[] args)
        {
            N = Sarray()[0];
            A = Sarray();
            anums = new int[4];
            foreach (var a in A)
                ++anums[a];
            dp = new double[N + 1, N + 1, N + 1];
            WriteLine(exv());

        }
        static double exv()
        {
            if (dp[anums[1], anums[2], anums[3]] != 0) return dp[anums[1], anums[2], anums[3]];
            var zeronum = anums[0];
            if (zeronum == N) return 0;
            double ans = 0;
            for (var i = 1; i <= 3; ++i)
            {
                if (0 == anums[i]) continue;
                double dbl = anums[i];
                ++anums[i - 1];
                --anums[i];
                dp[anums[1], anums[2], anums[3]] = exv();
                ans += 1.0 / (N - zeronum) * dbl * dp[anums[1], anums[2], anums[3]];
                ++anums[i];
                --anums[i - 1];
            }
            double next = (double)N / (N - zeronum);
            return ans + next;
        }
    }
}

Measured memory_bytes: 226516
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  bool can = false;
  for (int i=0; i<=N; i++) {
    for (int j=0; j<=M; j++) {
      if (i*(M-j)+(N-i)*j==K) {
        can = true;
        break;
      }
    }
    if (can) break;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	R, G, B, N := ReadInt(), ReadInt(), ReadInt(), ReadInt()

	ans := 0
	for r := 0; r*R <= N; r++ {
		for g := 0; r*R+g*G <= N; g++ {
			b := N - (r*R + g*G)
			if b >= 0 && b%B == 0 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	v, e := strconv.Atoi(Read())
	if e != nil {
		panic(e.Error())
	}
	return v
}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

const int MAX = 300010;

int op(int a, int b){
  return max(a,b);
}

int e(){
  return 0;
}

int main(){
  int N, K;
  cin >> N >> K;
  segtree<int,op,e> seg(MAX);
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    int l = max(0,x-K);
    int r = min(MAX,x+K+1);
    int A = seg.prod(l,r);
    seg.set(x,A+1);
  }
  
  int ans = 0;
  for(int i=0; i<MAX; i++){
    ans = max(ans,seg.get(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 8584
#include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	// prime numbers table
	vector <bool> isPrime( 10001, false );
	isPrime[2] = true;
	for ( int i = 3; i < 10001; i += 2 )
	{
		isPrime[i] = true;
	}

	for ( int i = 3; i < 10001; i += 2 )
	{
		for ( int j = i + i; j <= 10001; j += i )
		{
			isPrime[j] = false;
		}
	}

	
	int N;
	while ( cin >> N )
	{
		int kotae = 0;
		int i, j;
		for ( i = 1, j = N; i <= N && j >= 1; i++, j-- )
		{
			if ( isPrime[i] && isPrime[j] )
				kotae++;
		}
		cout << kotae << endl;
	}

	return 0;
}

Measured memory_bytes: 0
//
// Created by Tetsuya Shiota on 2019/03/09.
//

#include<iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

    vector<pair<int, int> > V(N);

    for(auto &v : V){
        cin >> v.first >> v.second;
    }

    sort(V.begin(), V.end());

    ll cost = 0;
    for(auto &v : V){
        ll num = min(M, v.second);
        M -= num;
        cost += num * v.first;
    }
    cout << cost <<endl;




}

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

int main(){
    long long N,X,M;
    cin >> N >> X >> M;

    //ex
    if(N==1){
        cout << X << endl;
        system("pause");
        return 0;
    }


    long long visited[M];
    fill(visited,visited+M,-1);
    visited[X]=1;
    long long Y;
    long long fi,se;
    long long X_sub=X;
    while(1){
        Y=(X_sub*X_sub)%M;
        if(visited[Y]<0){
            visited[Y]=visited[X_sub]+1;
            X_sub=Y;
            if(visited[Y]==N){
                fi=1;
                se=N;
            }
        }else{
            fi=visited[Y];
            se=visited[X_sub];
            break;
        }
    }
    long long A[200000];
    long long i;
    A[1]=X;
    for(i=2; i<=se; i++){
        A[i]=(A[i-1]*A[i-1])%M;
    }
    long long ans=0;
    for(i=1; i<=fi-1; i++){
        ans+=A[i];
    }
    long long val=0;
    N-=(fi-1);
    for(i=fi; i<=se; i++){
        val+=A[i];
    }
    ans+=val*(N/(se-fi+1));
    N%=(se-fi+1);
    if(N>0){
        for(i=fi; i<=se; i++){
            ans+=A[i];
            N--;
            if(N==0) break;
        }
    }
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 4780
#include<iostream>
#include<algorithm>
#include<set>

using namespace std;

typedef struct event
{
    int poz,ind;
} EVENT;

EVENT Ev[100005];
int A[100005],B[100005],ValSt[100005];

bool cmp(EVENT a, EVENT b)
{
    if(a.poz!=b.poz)
        return a.poz<b.poz;
    return B[a.ind]>B[b.ind];
}

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

    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>A[i]>>B[i];
        Ev[i]={A[i],i};
    }

    sort(Ev+1,Ev+n+1,cmp);

    set<int> Min;
    for(int i=1; i<=n; i++)
    {
        Min.insert(B[Ev[i].ind]);
        int dr=*Min.begin();
        ValSt[i]=max(0,dr-Ev[i].poz+1);
    }

    Min.clear();
    int prv=0;
    int rez=0;
    for(int i=n; i>=2; i--)
    {
        Min.insert(B[Ev[i].ind]);
        int dr=*Min.begin();
        prv=max(0,dr-Ev[n].poz+1);
        rez=max(rez,prv+ValSt[i-1]);
    }

    for(int i=1; i<=n; i++)
        rez=max(rez,B[i]-A[i]+1+ValSt[n]);

    cout<<rez<<"\n";
    return 0;
}


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

int main(){
    int N;
    int *p;
    int count, i, tmp, j, r = 0, l = 0, flag=0;
    int index[2];

    scanf("%d", &N);
    getchar();
    p = (int *)malloc(sizeof(int) * N);
    for(i=0; i<N; i++){
        scanf("%d", &p[i]);
    }
    
    j=0; count=0;
    for(i=0; i<N-1; i++){
        if(p[i] > p[i+1]){
            count++;
            if(j < 2){
                index[j] = i;
                j++;
            }
        }
    }
    //printf("%d\n", count);

    if(count < 3){
        if(count == 0){
            flag = 1;
        }else if(count == 1){
            tmp = p[index[0]];
            p[ index[0] ] = p[ index[0]+1 ];
            p[ index[0]+1 ] = tmp;

            count = 0;
            for(i=0; i<N-1; i++){
                if(p[i] > p[i+1]){
                    count++;
                }
            }
            if(count == 0)flag = 1;
            
        }else{
            tmp = p[ index[0] ];
            p[ index[0] ] = p[ index[1]+1 ];
            p[ index[1]+1 ] = tmp;

            count = 0;
            for(i=0; i<N-1; i++){
                if(p[i] > p[i+1]){
                    count++;
                }
            }
            if(count == 0)flag = 1;
        }
    }
    
    /*for(i=0; i<N; i++){
        printf("%d ", p[i]);
    }*/

    if(flag == 1){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    
}

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

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

  LL ans = 0;
  for (int b = 1; b <= n; b ++) {
    int p = n / b;
    int r = n % b;
    LL sum = p * max(0, b - k) + max(0, r - k + 1);
    if (k == 0) sum --;
    ans += sum;
  }
  cout << ans << endl;
}

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

int partition(int *,int);

int main(){
  int *A,n,i,box;

  scanf("%d",&n);
  A = (int *)malloc(1 + n * sizeof(int));
  for(i = 1;i < n + 1;i++) scanf("%d",&A[i]);

  box = partition(A,n);


  for(i = 1;i < box;i++) printf("%d ",A[i]);
  printf("[%d] ",A[box]);
  for(i = box + 1;i < n + 1;i++){
    printf("%d",A[i]);
    if(i != n) printf(" ");
  }
  printf("\n");
  
  free(A);
  return 0;
}

int partition(int *A,int n){
  int x,i,j,hako;
  x = A[n];
  i = -1;
  for(j = 0;j < n;j++){
    if(A[j] <= x){
      i += 1;
      hako = A[i];
      A[i] = A[j];
      A[j] = hako;
    }
  }
  hako = A[i + 1];
  A[i + 1] = A[n];
  A[n] = hako;
  
  return i + 1;
}



Measured memory_bytes: 2100
#include <iostream>
using namespace std;
int d[] = {5, 2};
bool msN[300000];

bool checkMSN(int x) {
	int k = 0;
	for (int i = 6; i < x; k = (k + 1) % 2, i += d[k]) {
		if (x % i == 0) {
			return false;
		}
	}
	msN[x] = true;
	return true;
}

int main() {
	int n;
	while (cin >> n, n != 1) {
		cout << n << ":";
		int k = 0;
		int outCount = 0;
		for (int i = 6; i <= n; k = (k + 1) % 2, i += d[k]) {
			if (n % i == 0 && (msN[i] || checkMSN(i))) {
				cout << " " << i;
				outCount++;
			}
		}
		if (outCount == 0) cout << " " << n << endl;
		else cout << endl;
	}
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> counts(27, 1);
    for (char c : s) counts[c - 'a']++;

    mint ans = 1;
    for (int i : counts) ans *= i;

    ans = ans - 1;

    cout << ans << endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  char canpas[50][51];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> canpas[i][j];
    }
  }

  bool ispaint = true;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (canpas[i][j] == '#' && (canpas[i][j + 1] == '#' || canpas[i + 1][j] == '#' || canpas[i - 1][j] == '#' || canpas[i][j - 1] == '#')) {
        ispaint = true;
      } else if (canpas[i][j] == '#') {
        ispaint = false;
        break;
      }
    }

    if (!ispaint) { break; }
  }

  if (ispaint) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
    int n;
    scanf("%d",&n);
    bool card[4][13];
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            card[i][j] = true;
        }
    }
    for(int i = 0; i < n; i++){
        char c;
        scanf("\n%c",&c);
        int a;
        scanf("%d",&a);
        if(c == 'S'){
            card[0][a - 1] = false;
        }
        else if(c == 'H'){
            card[1][a - 1] = false;
        }
        else if(c == 'C'){
            card[2][a - 1] = false;
        }
        else if(c == 'D'){
            card[3][a - 1] = false;
        }
    }
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            if(card[i][j]){
                if(i == 0){
                    printf("S %d\n",j + 1);
                }
                else if(i == 1){
                    printf("H %d\n",j + 1);
                }
                else if(i == 2){
                    printf("C %d\n",j + 1);
                }
                else if(i == 3){
                    printf("D %d\n",j + 1);
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2756
n = int(input())
abc = []
for i in range(n):
    abc.append([int(i) for i in input().split()])

dp = [[0,0,0] for i in range(n)]

for i in range(n):
    if i != 0:
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i][j] = max(dp[i][j],dp[i-1][k] + abc[i][j])
    else:
        for j in range(3):
            dp[i][j] = abc[i][j]
print(max(dp[n-1]))
#print(dp)


Measured memory_bytes: 76248
import java.io.BufferedReader;
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream("./input.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] s = new int[n+1];
		String[] l = br.readLine().split(" ");
		for(int i = 0; i < n; ++i){
			s[i] = Integer.parseInt(l[i]);
		}
		int q = Integer.parseInt(br.readLine());
		int[] t = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		
		int cnt = 0;
		for(int i = 0; i < q; ++i) {
			s[n] = t[i];
			int j = 0;
			while(t[i] != s[j]) {
				j += 1;
			}
			if(j != n){
				cnt += 1;
			}
		}
		System.out.println(cnt);
	}

}

Measured memory_bytes: 32304
n = int(input())
dic = {}
list = [int(i) for i in input().split()]
for i in list:
    if i not in dic:
        dic[i] = 0
    dic[i] += 1
q = int(input())
ans = sum(list)
for j in range(q):
    b,c = (int(x) for x in input().split())
    if b not in dic:
        print(ans)
        continue
    else:
        if c not in dic:
            dic[c] = dic[b]
        else:
            dic[c] += dic[b]
    ans = ans + (c-b)*dic[b]
    dic[b] = 0
    print(ans)


Measured memory_bytes: 21252
import math
def fib(q):
   fibonacci = [0,1]
   for i in range(2,q):
       fibonacci.append(fibonacci[i-2]+fibonacci[i-1])
   return fibonacci[q-1]
n,m = list(map(int, input("").split()))
a=[]
a.append(-1)
for i in range(m):   
    a.append(int(input()))
a.append(n+1)
out=1
c=10**9+7
for i in range(m+1):
    out*=int(fib(a[i+1]-a[i]))
    out%=c
print(out)

Measured memory_bytes: 465836
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M;
  cin >> N >> M;
  vector<int> a(M),b(M);
  vector<bitset<12>> c(M);
  for(int i=0;i<M;i++){
    cin >> a.at(i) >> b.at(i);
    for(int j=0;j<b.at(i);j++){
      int tmp;
      cin >> tmp;
      c.at(i).set(tmp-1);
    }
  }

  vector<int> dp((1<<N),1e9);
  dp.at(0)=0;
  for(int i=0;i<M;i++){
    for(int bit=0;bit<(1<<N);bit++){
      int tmp=c.at(i).to_ullong();
      dp.at(bit|tmp)=min(dp.at(bit|tmp),dp.at(bit)+a.at(i));
    }
  }
  if(dp.at((1<<N)-1)==1e9)  cout << -1 << endl;
  else  cout << dp.at((1<<N)-1) << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
A = []
ans = 1
L.sort()

for i in range (N):
  ans*= L[i]
  if ans == 0 or ans > 10**18:
    break
if ans > 10**18:
  print(-1)
else:
  print(ans)


Measured memory_bytes: 21596
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int[][] a, b;
	int[][] tmp;
	int n;

	void run(){
		n=10;
		for(int m=sc.nextInt(); m>0; m--){
			a=new int[n][n];
			for(int j=0; j<n; j++){
				for(int i=0; i<n; i++){
					a[j][i]=sc.nextInt();
				}
			}
			solve();
		}
	}

	void solve(){
		tmp=new int[n][n];
		b=new int[n][n];
		for(int sup=0; sup<1<<n; sup++){
			for(int j=0; j<n; j++){
				System.arraycopy(a[j], 0, tmp[j], 0, n);
				Arrays.fill(b[j], 0);
			}
			for(int i=0; i<n; i++){
				if(((sup>>i)&1)!=0){
					reverse(i, 0);
				}
			}
			for(int j=1; j<n; j++){
				for(int i=0; i<n; i++){
					if(tmp[j-1][i]==1){
						reverse(i, j);
					}
				}
			}
			int c=0;
			for(int i=0;i<n;i++){
				c+=tmp[n-1][i];
			}
			if(c==0){
				for(int j=0;j<n;j++){
					for(int i=0;i<n;i++){
						print(b[j][i]+(i==n-1?"\n":" "));
					}
				}
				return;
			}
		}
	}

	void reverse(int x, int y){
		int[] dx={0, 0, 0, -1, 1};
		int[] dy={0, -1, 1, 0, 0};
		for(int i=0; i<5; i++){
			int x2=x+dx[i];
			int y2=y+dy[i];
			if(x2>=0&&x2<n&&y2>=0&&y2<n){
				tmp[y2][x2]=1-tmp[y2][x2];
			}
		}
		b[y][x]=1-b[y][x];
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

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

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

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
x,y=map(int,input().split())
if x==0:
  if y<0:
    print(-1*y+1)
  else:
    print(y)
    
elif x>0:
  if -1*x<y<x:
    if y<=0:
      print(y+x+1)
    else:
      print(x-y+2)
  elif x<y:
    print(y-x)
  else:
    print(-1*y-x+1)
    
else:
  if x<y<-1*x:
    if y<=0:
      print(y-x)
    else:
      print(-1*y-x+1)
  elif y<x:
    print(-1*y+x+2)
  else:
    print(y+x+1)


Measured memory_bytes: 38384
#include <numeric>
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] != '9') {
            cout << s[0] - '1' + 9 * (s.size() - 1) << endl;
            return 0;
        }
    }
    cout << accumulate(s.begin(), s.end(), 0) - s.size() * '0' << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		
		int a;
		int max=sc.nextInt();
		int min=max;
		long g=max;
		
		for (int i=1;i<n;i++){
			a=sc.nextInt();
			g=g+a;
			if(max<a) max=a;
			if(min>a) min=a;
		}
		System.out.println(min+" "+max+" "+g);
	}

}

Measured memory_bytes: 31744
/*
                " اللهم صلي و سلم علي سيدنا محمد و علي اله وصحبه اجمعين "
*/

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define intial(s1, s2, x, dp) f(int i = 0; i < s1; i++) f(int j = 0; j < s2; j++) dp[i][j] = x;
using namespace std;
#define BI acos(-1)
#define all(a) a.begin(), a.end()
#define loop1(n) f(int i = 0; i < n; i++)
#define loop2(n) f(int j = 0; j < n; j++)
#define oo 1e9;
void Open()
{
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void madesetprobblem()
{
    //$ $
    //less than or equal => $ 1 \leq 100 $
    //  $(1 \le A,B \le 10^5 )$
    // a[i] => $a_i$
    // a[i][j] => $a_{i,j}$
    // double qoutes ''yext''
    /*
        image
        \begine{center}
        \includegraphics{image.jpg}
        \end{center}
    */
    /*
        list
        \begin{itemize}
            \item first one
            \item second one
        \end{itemize}
    */
}
ll n,*a,*b;
ll dp[401][401];
ll ans(int i,int j)
{
    ll& ret=dp[i][j];
    if(~ret)return ret;
    if(j-i==0)
    {
        return ret=0;
    }
    if(j-i==1)
    {
        return ret=a[i]+a[j];
    }
    if(j-i==2)
    {
        return ret=min(a[i]+2*a[i+1]+2*a[i+2],2*a[i]+2*a[i+1]+a[i+2]);
    }
    ret=1e14;
    f(int c=i;c<=j;c++)
    {
        ll x=(ans(i,c)+(b[c+1]-b[i]))+(ans(c+1,j)+(b[j+1]-b[c+1]));
      //  cout<<x<<' '<<i<<' '<<j<<endl;
        ret=min(ret,x);
    }
    return ret;
}
int main()
{
    //Open();
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(dp,-1,sizeof dp);
    cin>>n;
    a=new ll[n];
    b=new ll[n+1];
    memset(b,0,sizeof b);
    loop1(n)
    {
        cin>>a[i];
        b[i+1]=a[i]+b[i];
    }
    if(n==1)
    {
        cout<<a[0];
        return 0;
    }
    cout<<ans(0,n-1);
}


Measured memory_bytes: 4884
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>

  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  typedef long double lld;
  typedef string str;
  typedef unsigned long long ull;
  ll INF = INT_MAX;
  // ll mod = 998244353;
  lld PI = 3.141592653;

// const int N = 2e5 + 5;

// int a[N];
// int n,k;



// void solve(){

// string s;
// cin>>s;


// }
 

  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
      
     
      int a;
      cin>>a;
      cout<< a*(1+a+a*a)<<"\n";
}



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

int main() {
  int N;
  cin >> N;
  string str;
  cin >> str;
  long long count = 0;
  long long countR = 0;
  long long countG = 0;
  long long countB = 0;
  for (int i = 0; i < N; i++) {
    if (str.at(i) == 'R') {
      countR++;
    } else if (str.at(i) == 'G') {
      countG++;
    } else {
      countB++;
    }
  }
  for (int i = 0; i < N; i++) {
    if (str.at(i) == 'R') {
      for (int k = i + 1; k < N; k++) {
        if (str.at(k) == 'B' && 2 * k - i < N) {
          int l = 2 * k - i;
          if (str.at(l) == 'G') {
              count++;
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (str.at(i) == 'R') {
      for (int j = i + 1; j < N; j++) {
        if (str.at(j) == 'G' && 2 * j - i < N) {
          int k = 2 * j - i;
          if (str.at(k) == 'B') {
            count++;
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (str.at(i) == 'G') {
      for (int j = i + 1; j < N; j++) {
        if (str.at(j) == 'R' && 2 * j - i < N) {
          int k = 2 * j - i;
          if (str.at(k) == 'B') {
            count++;
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (str.at(i) == 'G') {
      for (int j = i + 1; j < N; j++) {
        if (str.at(j) == 'B' && 2 * j - i < N) {
          int k = 2 * j - i;
          if (str.at(k) == 'R') {
            count++;
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (str.at(i) == 'B') {
      for (int j = i + 1; j < N; j++) {
        if (str.at(j) == 'R' && 2 * j - i < N) {
          int k = 2 * j - i;
          if (str.at(k) == 'G') {
            count++;
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (str.at(i) == 'B') {
      for (int j = i + 1; j < N; j++) {
        if (str.at(j) == 'G' && 2 * j - i < N) {
          int k = 2 * j - i;
          if (str.at(k) == 'R') {
            count++;
          }
        }
      }
    }
  }
  cout << countR * countB * countG - count << endl;
}

Measured memory_bytes: 3524
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        if(n % 1000 == 0) System.out.println(0);
        else System.out.println(1000 - n%1000);
    }
}


Measured memory_bytes: 35540
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static boolean judge(int num){
		boolean result;
		if(0<num && num<=100){
			result = true;
		}
		else{
			result = false;
		}
		return result;
	}
	public static int power(int num){
		int pow = num*num*num;
		return pow;
	}
	public static void main(String[] args) throws IOException{

		//??£?¨???¨??\???
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();

		if(judge(num) == true){
		 System.out.println(power(num));
		}
		else if(judge(num) == false){
			System.out.println("1~100??§??\?????????????????????.???????????????.");
		}

		}

	}

Measured memory_bytes: 26412
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <cmath>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ll も int も longlongにしてしまう
    #define int long long

    int H, W; cin >> H >> W;
    vector<string> S;
    string header;
    REP(i, W+2) header += ".";
    S.push_back(header); 
    REP(h, H) {
        string s; cin >> s;
        s = "." + s + ".";
        S.push_back(s);
    } 
    S.push_back(header);

    bool possible = true;

    REP(h, H) {
        REP(w, W) {
            if (S[h+1][w+1] == '#') {
                if (S[h][w+1] == '.' && S[h+1][w] == '.' && S[h+1][w+2] == '.' && S[h+2][w+1] == '.') {
                    possible = false;
                }
            }
        } 
    } 
    
    if (possible) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

using namespace std;

int GCB(int x,int y)
{	
	int z = y;
	y = x % y;
	x = z;
	
	if(y==0)return x;
	
	return GCB(x,y);
}

int main()
{	
	int x,y;
	cin >> x >> y;
	
	if(x<y){
		int z = x;
		x = y;
		y = z;
	}
	cout << GCB(x,y) << endl;
	
	return 0;
}

Measured memory_bytes: 1160
n = gets.to_i
a, b, c = 3.times.map { gets.split.map(&:to_i).sort }
ans = 0
n.times {|i|
  if bc = c.bsearch_index {|x| x > b[i]}
    ab = a.bsearch_index {|x| x >= b[i]} || n
    ans += ab * (n - bc)
  end
}
p ans


Measured memory_bytes: 24680
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(){
    int n; cin >> n;
    unordered_map<int, int> mp;
    for(int i=2; i<=n; ++i){
        int t=i;
        for(int j=2; t>1; ++j){
            while(t%j==0){
                ++mp[j];
                t/=j;
            }
        }
    }

    int ans=0;
    {
        int x=0, y=0;
        for(auto& p : mp){
            if(2 <= p.second && p.second <= 3) ++x;
            else if(p.second >= 4) ++y;
        }
        if(y>1){
            ans+=x*y*(y-1)/2;
            ans+=y*(y-1)*(y-2)/2;
        }
    }
    {
        int x=0, y=0;
        for(auto& p : mp){
            if(4 <= p.second && p.second <= 13) ++x;
            else if(p.second >= 14) ++y;
        }
        ans+=x*y;
        ans+=y*(y-1);
    }
    {
        int x=0, y=0;
        for(auto& p : mp){
            if(2 <= p.second && p.second <= 23) ++x;
            else if(p.second >= 24) ++y;
        }
        ans+=x*y;
        ans+=y*(y-1);
    }
    {
        int x=0;
        for(auto& p : mp){
            if(p.second >= 74) ++x;
        }
        ans+=x;
    }
    cout << ans << endl;
    return 0;
}


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

int min_operation(int N){
    int s_max, n_max, s_res, n_res, res;
    if(N < 6){
        return N;
    }

    s_max = 1;
    for(int i=0;; i++){
        if((s_max*6) > N){
            break;
        }
        s_max *= 6;
    }
    n_max = 1;
    for(int i=0;; i++){
        if((n_max*9) > N){
            break;
        }
        n_max *= 9;
    }

    s_res = 1 + min_operation(N - s_max);
    n_res = 1 + min_operation(N - n_max);
    res = min(s_res, n_res);

    return res;
}

int main(){
    int N;
    cin >> N;
    cout << min_operation(N) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second

 
 
using namespace __gnu_pbds;
using namespace std;
 const int mod=1e9+7;
 // const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i; 
int multiply(int a, int b, int in_mod){return (a*b)%in_mod;} 
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);
        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}

// const int MAXN=5e5+10;
// vector<int> fac(MAXN);
// vector<int> infac(MAXN);
// void build_factorial()
// {
//     fac[0]=1;
//     infac[0]=1;
//     for(int i=1;i<MAXN;i++)
//     {
//         fac[i]=(fac[i-1]*i)%mod;
//         infac[i]=mod_inv(fac[i], mod);
//     }
// }



// void solve()
// {
//     int h, w, n;
//     cin>>h>>w>>n;
//     vector<pair<int, int> > bad;
//     for(int i=0;i<n;i++)
//     {
//         int r, c;
//         cin>>r>>c;
//         bad.pb({r,c});
//     } 
//     sort(all(bad));
//     bad.pb({h, w});



//     int ways[n+1];
//     for(int i=0;i<=n;i++)
//     {

//         ways[i] = (fac[bad[i].fi+bad[i].se-2]*infac[bad[i].fi-1])%mod * infac[bad[i].se-1]%mod;
//         for(int j=0;j<=i;j++)
//         {
//             if(bad[j].fi<=bad[i].fi && bad[j].se<=bad[i].se)
//             {
//                 ways -= 
//             }
//         }
//     }
// }


void solve()
{
    int a, b, n;
    cin>>a>>b>>n;
    int mx=0;

    mx=max(mx, (a*(min(n, b-1))/b));
    cout<<mx<<endl;
}

 
 
signed main()
 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        if(fopen("INPUT.txt","r"))
        {
            freopen ("INPUT.txt" , "r" , stdin);
            freopen ("OUTPUT.txt" , "w" , stdout);
        }
    #endif
    auto clk=clock(); 
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------     
 
    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        solve();
        // cout<<endl;
 
    }
 
    // -------------------------------------Code ends here------------------------------------------------------------------
 
 
    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
 }


Measured memory_bytes: 3804
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))


S = str(input())
T = str(input())

ans = 0
for i in range(3):
    if S[i] == T[i]:
        ans += 1

print(ans)


Measured memory_bytes: 6856
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

const long long MOD = 1000000007;

vector<int> places[210000];
long long dp[210000];
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
int main() {
    // 入力
    int N; cin >> N;
    vector<int> c(N);
    for (int i = 0; i < N; ++i) cin >> c[i];

    // places[i] := (c[j] = i となるような j の集まり)
    for (int i = 0; i < 210000; ++i) places[i].clear();
    for (int i = 0; i < N; ++i) places[c[i]].push_back(i);

    // DP
    dp[0] = 1;
    for (int i = 1; i <= N; ++i) {
        // 特に操作しない場合
        add(dp[i], dp[i-1]);

        // 操作する場合
        int color = c[i-1];
        int it = lower_bound(places[color].begin(), places[color].end(), i-1)
            - places[color].begin(); // c[i] が color 色の何番目の要素か
        if (it > 0) {
            int j = places[color][it - 1]; // c[j] = c[i] となる j
            if ((i-1) - j > 1) add(dp[i], dp[j+1]);
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 13824
N = int(input())
uvw = [list(map(int,input().split())) for _ in range(N-1)]
import sys
sys.setrecursionlimit(10000000)
#testcase = open('testcase_04','r')
#contents = testcase.read()
#contents = contents.split("\n")
#N = int(contents[0])
#uvw = [[0,0,0] for _ in range(N-1)]
#for i in range(N-1):
#    uvw[i] = [int(j) for j in contents[i+1].split()]
        


ans = [0] * N
adj_list = [[] for _ in range(N+1)]

for u,v,w in uvw:
    adj_list[u-1].append([v-1,w])
    adj_list[v-1].append([u-1,w])
    
memo = [True] * N
def dfs(s,cnt): 
    memo[s] = False
    if cnt % 2 == 1:
        ans[s] = 1
    nxt = adj_list[s]
    for v,w in nxt:
        if memo[v]:
            dfs(v,cnt+w)
    return
    
dfs(0,0)
for a in ans:
    print(a)
    

    


Measured memory_bytes: 107172
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 22;
const int DX[] = {1, 0, -1, 0};
const int DY[] = {0, 1, 0, -1};
string grid[N];
int dist[N][N];
int n, m;

int bfs(int sx, int sy, int ex, int ey) {
    if(grid[sx][sy] == '#') return 1e9;
    rep(i, 1, n) {
        fill(dist[i] + 1, dist[i] + m + 1, 1e9);
    }
    queue<pair<int, int> > q;
    dist[sx][sy] = 0;
    q.push({sx, sy});
    while(q.size()) {
        pair<int, int> pos = q.front();
        q.pop();
        rep(d, 0, 3) {
            int x = pos.fi + DX[d];
            int y = pos.se + DY[d];
            if(grid[x][y] == '#') continue;
            if(dist[x][y] > dist[pos.fi][pos.se] + 1) {
                dist[x][y] = dist[pos.fi][pos.se] + 1;
                q.push({x, y});
            }
        }
    }
    return dist[ex][ey];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    grid[0] = string(m + 2, '#');
    grid[n + 1] = string(m + 2, '#');
    rep(i, 1, n) {
        string s;
        cin >> s;
        grid[i] = '#' + s + '#';
    }
    int ans = 0;
    rep(sx, 1, n) {
        rep(sy, 1, m) {
            rep(ex, 1, n) {
                rep(ey, 1, m) {
                    int d = bfs(sx, sy, ex, ey);
                    if(d < 1e9) {
                        ans = max(ans, d);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt=1;
void init(){cnt=1,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	ll n;
  	cin>>n;
  	cout<<(n+n*n+n*n*n)<<endl;
	return 0;
}


Measured memory_bytes: 3644
N = int(input())

p = [[ 0 for i in range(3)] for j in range(N+1)]

for i in range(1,N+1):
    p[i][0], p[i][1], p[i][2] = map(int,input().split())

cant = True

if p[1][0] % 2 == (p[1][1] + p[1][2]) % 2 and p[1][0] >= p[1][1] + p[1][2]:
    cant = False

if cant:
    print('No')
    exit()

if N > 1:
    for i in range(1, N+1):
        ts = p[i][0] - p[i-1][0]
        ps = p[i][1] - p[i-1][1] + p[i][2] - p[i-1][2]
        if ts%2 == ps%2 and ts*ts >= ps*ps:
            cant = False
        else:
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 21108
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<functional>
#include<array>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> array(n);
	long long ans,ans2=0,width;
	for (int i = 0;i < n;i++) cin >> array[i];
	sort(array.begin(), array.end(), greater<int>());
	ans = (array[0] + 1) / 2;
	width = array[0];
	if (n == 2) { cout << array[0] << " " << ans2 << endl; return 0; }
	for (int i = 0; i < n;i++)
	{
		if (abs(array[i] - ans) < width) {
				ans2 = array[i];
				width = abs(array[i] - ans);		
		}
		

	}

	cout << array[0] << " " << ans2 << endl;


	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <utility>
#include <cmath>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=0, x=0, y=0, n;
    int tn, xn, yn;
    int md, dt;
    bool j=true;
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>tn>>xn>>yn;
        md=abs(xn-x)+abs(yn-y);
        dt=tn-t;
        if(md>dt || (md-dt)%2!=0){
            j=false;
            break;
        }
        t=tn;
        x=xn;
        y=yn;
    }
    if(j) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    cout << (n - 2) * 180 << endl;

    return 0;
}


Measured memory_bytes: 256