akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

#define ll long long

int main()
{
    int n, ans = 0; ll d;
    cin >> n >> d;
    for (int i = 1, x, y; i <= n; i++)
    {
        cin >> x >> y;
        if (0LL + 1LL * x * x + 1LL * y * y <= d * d) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  cin>>s>>t;
  int dp[s.size() + 1][t.size() + 1];
  for(int i=0; i<=s.size(); i++){
    for(int j=0; j<=t.size(); j++){
      if(i == 0 || j == 0){
        dp[i][j] = 0;
        continue;
      }
      if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
      else
         dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  }
  string ans = "";
  for(int i=s.size(), j = t.size(); i>0 && j>0; ){
    //if(s[i-1] == t[j-1]){
    if(dp[i][j] != max(dp[i-1][j], dp[i][j-1])) {
      ans += s[i-1];
      i--, j--;
      continue;
    }
    if(dp[i][j] == dp[i-1][j]){
      i--;
      continue;
    }
    else{
      j--;
      continue;
    }
  }
  //cout<<dp[s.size()][t.size()];
  reverse(ans.begin(), ans.end());
  cout<<ans;
  return 0;
}

 
        	


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

using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 50;

int grid[N+2][N+2];
bool vis[N+2][N+2];

void floodfill(int i, int j){
	if(grid[i][j] == 0) return;
	if(vis[i][j]) return;
	
	vis[i][j] = true;
	
	for(int x = -1; x <= 1; x++){
		for(int y = -1; y <= 1; y++){
			if (abs(x-y)==1){
				floodfill(i+x,j+y);
			}
		}
	}
}

bool checkSides(int i, int j){
	bool ans = false;
	for(int x = -1; x <= 1; x++){
		for(int y = -1; y <= 1; y++){
			if (abs(x-y)==1){
				if (grid[i+x][j+y] == 1){
					ans = true;
					break;
				}
			}
		}
		if (ans) break;
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int h, w; cin >> h >> w;
	
	memset(grid,0, sizeof(grid));
	memset(vis,false,sizeof(vis));
	
	for(int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			char ch; cin >> ch;
			grid[i][j] =  ch == '#';
		}
	}
	
	bool ans = true;

	for(int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			bool temp = true;
			if (grid[i][j] == 1) temp = checkSides(i,j);
			floodfill(i,j);
			
			if (!temp) {
				//cout << i << " " << j << " Yes" << endl;
				ans = false;
				break;
			}
		}
		if (!ans) break;
	}
	
	cout << ((ans) ? "Yes" : "No") << endl;
}

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

ostream& operator<<(ostream &out, string str) {
	for(char c : str) cout << c;
	return out;
}

template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}

template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}

void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}

#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second

template<class T> int size(T && a) {
	return a.size();
}

using LL = long long;
using PII = pair<int, int>;

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

	int n;
	cin >> n;
	vector<int> A(n);
	LL sum = 0 ;
	REP(i, n) {
		cin >> A[i];
		sum += A[i];
	}

	vector<LL> r(n);
	int it = 0;
	LL tot = 0;
	for(int i = 1; it < n; it++, i = (i + 2) % n) {
		int a = i - 1;
		if(a == -1) a += n;
		int b = i + 1;
		if(b == n) b -= n;
		
		r[b] = r[a] - A[a] + A[i];
		tot += r[b] * 2;
		debug(a, i, b, r[b]);
	}

	LL res = sum - tot;
	debug(res);
	res /= n;

	REP(i, n)
		cout << r[i] * 2 + res << " ";
	cout << "\n";
}


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

int main () {
  string S,T;
  cin >> S >> T;
  int N;
  N=S.size();
  for (int i=0; i<N; i++) {
    if (S.at(i)!=T.at(i)) {
      cout << "No" << endl;
      i=N;
    }
    if ((i==N-1)&&(S.at(i)==T.at(i))) {
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vbool vector<bool>
#define vvbool vector<vector<bool>>
#define INF 1000000009
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  rep(i,1000){
    int f = 0;
    vector<int> c = {i/100,i%100/10,i%10};
    rep(j,n){
      if(s[j] == '0' + c[f]){
        f++;
      }
      if(f == 3){
        count++;
        break;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
def bisect_left(L,x):
  lo=0
  hi=N
  while lo<hi:
    mid=(lo+hi)//2
    if L[mid]<x: lo=mid+1
    else: hi=mid
  return lo

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    """
    lo=0
    hi=N
    x=a+b
    while lo<hi:
      mid=(lo+hi)//2
      if L[mid]<x: lo=mid+1
      else: hi=mid
    ans+=lo-(j+1) 
    """
    ans+=bisect_left(L,a+b)-(j+1)
print(ans)


Measured memory_bytes: 74616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  //カードを降順にソート
  int N;
  cin >> N;
  vector<int> vec(N,0);
  for (int i = 0; i < N; i++){
    int a;
    cin >> a;
    vec.at(i) = a;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int d = 0;
  int j = 0;
  while (j < N){
    d += vec.at(j);
    j++;
    
    if (j == N){
      break;
    }
    else {
      d -= vec.at(j);
      j++;
    }
  }
  
  cout << d << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	ll n; cin >> n;
	map<string,int> d;
	ll ans = 0;
	rep(i,n){
		string s; cin >> s;
		d[s] += 1;
			
	}
	cout << (int)d.size() <<endl;
}

Measured memory_bytes: 19228
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(0);
 
    int n, k; cin >> n >> k;

    int a; cin >> a;

    int ma = a;
 
    for(int i = 0; i < n - 1; i++)
    {
        int x; cin >> x;

        a = __gcd(a, x);

        ma = max(ma, x);
    }

    string ans;
 
    if(ma < k || k % a) ans = "IMPOSSIBLE";
    else ans = "POSSIBLE";

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define fi first
#define se second
#define endl '\n'
#define int long long

const int N = 400001;
namespace Math{
	const int MAXN = 600005;
	int fac[MAXN], ifac[MAXN];
	const int MOD = 1000000007;
	int fpow(int a, int b, int mod = MOD) {
	    int res = 1;
	    while (b > 0) {
	        if (b & 1) res = res * a % mod;
	        a = a * a % mod;
	        b >>= 1;
	    }
	    return res;
	}
	int sum(int a, int b){
		int res = (a + b)%MOD;
		return res < 0 ? res + MOD: res;
	}
	int mul(int a, int b){
		return (a * b)%MOD;
	}
	void set_factorial(){
		fac[0] = fac[1] = 1;
		for(int i = 2 ; i < MAXN ; i ++)
			fac[i] = fac[i - 1] * i % MOD;
		ifac[MAXN - 1] = fpow(fac[MAXN - 1], MOD - 2);
		for(int i = MAXN - 2 ; i >= 0 ; i --)
			ifac[i] = ifac[i + 1] * (i + 1) % MOD;
	}
	int C(int a, int b){
		return ((fac[b]*ifac[a])%MOD)*ifac[b - a]%MOD;
	}
	int candy(int a, int b, int c){
		// chia a keo cho b nguoi min c
		return C(b - 1, a - b*(c - 1) - 1);
	}
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	using namespace Math;
	set_factorial();
	int empty = min(n - 1, k);
	int ans = 0;
	for(int i = 0; i <= empty; i ++){
//		cout << C(i, n) << " " << candy(i, n - i, 0) << endl;
		ans = sum(ans, mul(C(i, n), candy(i, n - i, 0)));
	}
	cout << ans;
}
	

Measured memory_bytes: 9600
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int flag=0,f=0;
for(int i=0;i<s.size();i+=2){
if(s[i]=='R' || s[i]=='U' ||s[i]=='D'){
flag=0;
}
else{
flag=1;
break;
}
}
for(int i=1;i<s.size();i+=2){
if(s[i]=='L'|| s[i]=='U' || s[i]=='D'){
f=0;
}
else{
f=1;
break;
}
}
if(flag==1|| f==1){
cout<<"No"<<endl;
}
else{
cout<<"Yes"<<endl;
}
}

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

using namespace std;
int n,i;
struct abc{
int v,poz;
}a[100005];
bool cmp(abc A,abc B)
{
    return A.v<B.v;
}
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i].v,a[i].poz=i;
    sort(a+1,a+n+1,cmp);
    for(i=1;i<=n;i++)
        cout<<a[i].poz<<' ';
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>

using namespace std ;

string lcs(string s1, string s2){
    int len1 = s1.length() ;
    int len2 = s2.length() ;
    
    vector<vector <int> > dp(len1+1, vector<int> (len2+1, 0)) ;
    
    for (int i=1 ; i<=len1 ; i++){
        for (int j=1 ; j<=len2 ; j++){
            if (s1[i-1] == s2[j-1])
                dp[i][j] = dp[i-1][j-1] + 1 ;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]) ;
        }
    }
    
    string comm_subseq ;
    stack<char> s ;
    
    int i=len1, j=len2 ;
    while(i>0 && j>0){
        if (s1[i-1] == s2[j-1]){
            s.push(s1[i-1]) ;
            i-- ;
            j-- ;
        }
        else{
            if (dp[i-1][j] >= dp[i][j-1])
                i-- ;
            else
                j-- ;
        }
    }
    
    while(!s.empty()){
        comm_subseq.push_back(s.top()) ;
        s.pop() ;
    }
    
    return comm_subseq ;
    
}

int main(){
    string s1, s2 ;
    cin >> s1 >> s2 ;
    
    cout << lcs(s1, s2) << "\n" ;
    
    return 0 ;
}


Measured memory_bytes: 38204
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double C = sc.nextDouble();

        double S = a * b * Math.sin(C/180.*Math.PI) / 2;

        double h = b * Math.sin(C/180.*Math.PI);
        
        double l = (a - b * Math.cos(C/180.*Math.PI));
        double c = Math.sqrt(h*h+l*l);
        double L = a + b + c;

        NumberFormat format = NumberFormat.getInstance();
        format.setMaximumFractionDigits(5);
        format.setMinimumFractionDigits(5);
        format.setGroupingUsed(false);
        System.out.println("" + format.format(S));
        System.out.println("" + format.format(L));
        System.out.println("" + format.format(h));
    }
}

Measured memory_bytes: 18612
#include <bits/stdc++.h>
using namespace std;
int main(){
	double a;
	double b;
	double h;
	double m;
	cin >> a >> b >> h >>m;
		double t=m/60;
	static const double pi = 3.141592653589793;
	double hk;
	double mk;
	hk= pi*(h+t)/6;
	mk= pi*m/30;
	double tl;
	tl= a*a+b*b - 2*a*b*cos(abs(hk-mk));
	double ans;
	ans = sqrt(tl);
	cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 4228
def merge(L,R):
  T=[]
  for l in L[::-1]:
    while R and R[-1] > l:
      T += [R.pop()]
    T += [l]
  return R+T[::-1]

def mergesort(A):
  l = len(A)
  global c
  c += l
  s = l // 2
  return merge(mergesort(A[:s]),mergesort(A[s:])) if l > 1 else A

def solver():
  print(*mergesort(list(map(int,input().split()))))
  print(c)

c = -int(input())


solver()




Measured memory_bytes: 63164
def sol():
    tmp=min([x**2+y**2,x**2+z**2,y**2+z**2])
    n=int(raw_input())
    for i in range(n):
        r=int(raw_input())
        print 'OK' if (r**2)*4>tmp else 'NA'

while 1:
    x,y,z=map(int,raw_input().split())
    if min(x,y,z)==0:
        break
    else:
        sol()

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

int w, h;
int t;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
char field[100][100];
bool masu[100][100];

void dfs(int a, int b){
	for(int i = 0; i < 4; i++){
		int nx = a+dx[i];
		int ny = b+dy[i];
		if(nx >= 0 && ny >= 0 && nx < w && ny < h && masu[ny][nx] == false && field[b][a] == field[ny][nx]){
			masu[ny][nx] = true;
			dfs(nx, ny);
		}
	}
}

void solve(){
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(masu[i][j] == false){
				masu[i][j] = true;
				dfs(j, i);
				t++;
			}
		}
	}
	cout << t << endl;
}

int main(){
	while(cin >> h >> w){
		if(h == 0 && w == 0) break;
		t = 0;
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 100; j++){
				masu[i][j] = false;
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){	
				cin >> field[i][j];
			}
		}
		solve();
	}
}

Measured memory_bytes: 1644
#include<iostream>
using namespace std;
int main(){
    long long int n,h[100000]={0},sum=0,a=0,f=-1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
        if(i>=1){
            if(h[i]<=h[i-1]){
                f=0;
                sum++;
            }
            else{
                f=1;
                a=max(a,sum);
                sum=0;
            }
            if(f==0&&i==n-1){
                a=max(a,sum);
            }
        }
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 1024
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

k=gets.to_i
queue=(1..9).to_a
while true
  if k<=queue.size
      puts queue[k-1]
      break
  end
  k-=1
  i=queue.shift
  d=i%10
  -1.upto(1) do|x|
    next if (x+d)<0 or (x+d)>9
    queue.push(i*10+d+x)
  end
end

Measured memory_bytes: 2504
#include<iostream>

using namespace std;

int main(){
  
  int m;
  
  cin>>m;
  
  for(int j=0;j<m;++j){
    int first;
    int year;
    int n;
    int max=0;
    
    cin>>first;
    cin>>year;
    cin>>n;
    
    for(int i=0;i<n;++i){
      int tnhk;
      double nenri;
      int tesu;
      
      cin>>tnhk>>nenri>>tesu;
      
      int A=first;
      int B;
      
      if(tnhk==1){
	for(int k=0;k<year;++k){
	  B=A*nenri;
	  A=A+B-tesu; 
	}
	if(max<A)
	  max=A;
      }
      
      else if(tnhk==0){
	int t=0;
	for(int k=0;k<year;++k){
	  B=A*nenri;
	  A=A-tesu;
	  t+=B;
	}
	if(max<A+t)
	  max=A+t;
      }
    }
    cout<<max<<endl;
  }
}

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

long long N;

bool isLarger(long long h, long long n, long long w) {
    return (4 * h * n * w < N * (h * n + n * w + w * h));
}

bool isEqual(long long h, long long n, long long w) {
    return (4 * h * n * w == N * (h * n + n * w + w * h));
}

int main()
{
    cin >> N;

    for (long long h = 1; h <= 3500; ++h) {
        for (long long n = h; n <= 3500; ++n) {
            long long w_min = 1, w_max = 3501;
            //printf("h = %lld, n = %lld\n", h, n);
            while (w_min + 1 < w_max) {
                long long w_mid = (w_min + w_max) / 2;
                //cout << w_mid << endl;
                if (isEqual(h, n, w_mid)) {
                    cout << h << " " << n << " " << w_mid << endl;
                    return 0;
                }
                if (isLarger(h, n, w_mid)) {
                    w_min = w_mid;
                } else {
                    w_max = w_mid;
                }
            }
            //int wait; cin >> wait;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
typedef string::const_iterator Cursol;
int num(Cursol&);
string calc(Cursol&);
string expr(Cursol&);

int pos ;

int num(Cursol& p){
  int ret = 0;
  while(isdigit(*p)){
    ret = ret * 10 + *p - '0';
    p++;
  }
  return ret;
}

string calc(Cursol& p){
  string ret;
  if(isdigit(*p)){
    int number = num(p);
    if( *p == '(') {
      string res = expr(++p);
      p++;
      while(number--){
        ret += res;
        if(pos < ret.size()) break;
      }
    } else {
      char c = *p++;
      while(number--){
        ret += c;
        if(pos < ret.size()) break;
      }
    }
  }else{
    while(isalpha(*p)){
      ret += *p++;
      if(pos < ret.size()) break;
    }
  }
  return ret;
}


string expr(Cursol& p){
  string ret;
  while( isalpha(*p) || isdigit(*p)){
    ret += calc(p);
    if(pos < ret.size()) break;
  }
  return ret;
}
int main(){
  string str;
  while(cin >> str >> pos, str!="0"||pos){
    Cursol idx = str.begin();
    string ret = expr(idx);
    if(pos < ret.size()) cout << ret[pos] << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 6088
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
//#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

bool s(int n){
    int a=n%10;
    while(n){
        if(n%10!=a)return 0;
        n/=10;
    }
    return 1;
}

signed main (){
    int n;cin>>n;
    while(1){
        if(s(n)){
            cout<<n<<endl;
            return 0;
        }
        n++;
    }

    
}
/*
1-21-2
*/


Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.readline())
X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

X = np.array(X, dtype=float)
Y = np.array(Y, dtype=float)

xa, xb = np.meshgrid(X, X)
ya, yb = np.meshgrid(Y, Y)
d = np.sqrt((xa - xb) ** 2 + (ya - yb) ** 2)
print(d.sum() / N)


Measured memory_bytes: 23024
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

	/*dp[i][j] i:i桁目 j 13で割った数 dp[i][j] 場合の数*/
	lli dp[100100][13]={0};

signed main(){

	string s;
	cin>>s;

	dp[0][0]=1;
	
	lli size=s.size();
	for(lli i=0;i<size;i++){
		int c;
		if(s.at(i)=='?')c=-1;
		else c = s.at(i)-'0';
		for(lli j=0;j<10;j++){
			if(c != -1 && c!=j)continue;
			for(lli ki=0;ki<13;ki++){
				dp[i+1][(ki*10+j)%13] += dp[i][ki];
			}
		}
		for(lli j = 0;j<13;j++)dp[i+1][j] %= MOD;
	}
	cout<<dp[size][5]<<endl;



	return 0;
}

Measured memory_bytes: 10624
s = int(input())
#h = [int(i) for i in input().split()]

a = s
ss = []

i = 0
while True:
    i += 1
    ss.append(a)
    if a % 2 == 0:
        a = int(a / 2)
    else:
        a = 3 * a + 1
    if a in ss:
        break

print(i+1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int M, L;
  M = N  / 10;
  L = N % 1000;
  if (N % 1111 == 0) {cout << "Yes" << endl;}
  else if (M % 111 == 0) {cout << "Yes" << endl;}
  else if (L % 111 == 0) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 3612
#include<iostream>

using namespace std;


int main() {


	int a, b;

	cin >> a >> b;

	if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
		cout << a * b << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N, M; cin >> N >> M;
  bool even[N] = {};
  rep(i,M) {
    int a, b; cin >> a >> b; a--; b--;
    even[a] ^= 1; even[b] ^=1;
  }
  string result = "YES";
  rep(i,N) if (even[i]%2==1) result = "NO";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

char s[20];

int main() {

	scanf("%s",s);

	int i;

	for (i = 0; i < 12; i++) {
		if (i == 3) { printf("%c ",s[i]); }
		else { printf("%c",s[i]); }
	}
	printf("\n");


	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n), sum_mod(n+1, 0);
	map<ll,ll> mp;
	ll ans = 0;
	rep(i,n){
		cin >> a[i];
		sum_mod[i+1] = (sum_mod[i] + a[i]) % m;
		if(sum_mod[i+1] == 0) ++ans;
		ans += mp[sum_mod[i+1]];
		mp[sum_mod[i+1]]++;
	}
	cout << ans << endl;
	return 0;
}

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

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

int main()
{
  int64_t a,b;
  cin>>a>>b;
  cout<<a*b/gcm(a,b)<<endl;
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var sx, sy, tx, ty int
	fmt.Fscan(r, &sx)
	fmt.Fscan(r, &sy)
	fmt.Fscan(r, &tx)
	fmt.Fscan(r, &ty)

	dx := tx - sx
	dy := ty - sy

	var ans []string
	// 1回目往復
	// 往路
	for i := 0; i < dx; i++ {
		ans = append(ans, "R")
	}
	for i := 0; i < dy; i++ {
		ans = append(ans, "U")
	}
	// 復路
	for i := 0; i < dx; i++ {
		ans = append(ans, "L")
	}
	for i := 0; i < dy; i++ {
		ans = append(ans, "D")
	}

	// 2回目往復
	// 往路
	ans = append(ans, "D")
	for i := 0; i < dx+1; i++ {
		ans = append(ans, "R")
	}
	for i := 0; i < dy+1; i++ {
		ans = append(ans, "U")
	}
	ans = append(ans, "L")
	// 復路
	ans = append(ans, "U")
	for i := 0; i < dx+1; i++ {
		ans = append(ans, "L")
	}
	for i := 0; i < dy+1; i++ {
		ans = append(ans, "D")
	}
	ans = append(ans, "R")

	fmt.Println(strings.Join(ans, ""))
}


Measured memory_bytes: 2048
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

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

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

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

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

const LL inf = 1e12;

LL solve(const LL H, const LL W)
{
    LL ans = inf;
    FOR(i,1,W) {
        const LL w = W-i;
        const LL a = H*i;
        if (w > 1) {
            const LL b = H*(w/2);
            const LL c = w*H - b;
            vector<LL> A = {a,b,c};
            sort(ALL(A));
            ans = min(ans,A[2]-A[0]);
        }
        if (H > 1) {
            const LL b = w*(H/2);
            const LL c = w*H - b;
            vector<LL> A = {a,b,c};
            sort(ALL(A));
            ans = min(ans,A[2]-A[0]);
        }
    }
    return ans;
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    LL H,W;
    while (cin >> H >> W) {
        const LL a = solve(H,W);
        const LL b = solve(W,H);
        const LL ans = min(a,b);
        cout << ans << endl;}
    return 0;
}


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

int main() {
  vector<string> vec{"Sunny" , "Cloudy" , "Rainy"};
   string s;
  cin >> s;
  for(int i = 0 ; i < 3 ; i++) {
    if(s == vec.at(i) && i != 2) {
      cout << vec.at(i + 1) << endl;
      break;
    }
    else if (s == vec.at(i) && i == 2) {
      cout << vec.at(0) << endl;
    }
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char cn[120000], * ci = cn + 20, ct, buf[8], * owa = cn + 119980;
//const ll ma0 = 1157442765409226768;
//const ll ma1 = 1085102592571150095;
//const ll ma2 = 71777214294589695;
//const ll ma3 = 281470681808895;
//const ll ma4 = 4294967295;
//inline int getint() {
//	memcpy(buf, ci, 8);
//	ll tmp = *(ll*)buf;
//	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
//	tmp = tmp << dig & ma1;
//	tmp = tmp * 10 + (tmp >> 8) & ma2;
//	tmp = tmp * 100 + (tmp >> 16) & ma3;
//	tmp = tmp * 10000 + (tmp >> 32) & ma4;
//	ci += (64 - dig >> 3) + 1;
//
//	if (ci - owa > 0) {
//		memcpy(cn, owa, 20);
//		ci -= 119980;
//		fread(cn + 20, 1, 119980, stdin);
//	}
//	return tmp;
//}
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	
	if (ci - owa > 0) {
		memcpy(cn, owa, 20);
		ci -= 119980;
		fread(cn + 20, 1, 119980, stdin);
	}

	return A;
}

char* di = cn;
const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[MAX * 6 + 10];
	int K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = K[i] + keta;
		}
	}
} f;
inline void putint(ll X) {
	int ue = X / 100000;
	if (ue) {
		for (int i = f.K[ue]; i < f.K[ue + 1]; i++)* di++ = f.C[i];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i];
	}
	else for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i];
	*di++ = '\n';
}

int B[200010];

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


	fread(ci, 1, 119980, stdin);

	int N = getint();
	ll kotae = 0;
	int A[200000];
	rep(i, N) kotae += B[(A[i] = getint())]++;
	int i = 0;
	
	int amari = N % 10000;
	int shou = N / 10000;
	rep(j, shou) {
		rep(k, 10000) putint(kotae - B[A[i++]] + 1);
		fwrite(cn, 1, di - cn, stdout);
		di = cn;
	}
	rep(k, amari) putint(kotae - B[A[i++]] + 1);
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

map<string, int> mp;

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

Measured memory_bytes: 256
N=int(input())
t,x,y=0,0,0
ans="Yes"
for i in range(N):
  T,X,Y=map(int,input().split())
  r=abs(X-x)+abs(Y-y)
  t=T-t
  if r%2!=t%2 or t<r:
    ans="No"
    break
  t=T
  x=X
  y=Y
print(ans)


Measured memory_bytes: 8924
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// list up all factors
template <typename T>
set<T> factors(T a) {
    set<T> facs;
    for (T i = 1; i * i <= a; ++i) {
        if (a % i == 0) {
            facs.insert(i);
            facs.insert(a / i);
        }
    }
    return facs;
}

// greatest common divisor and least common multiple
// gcd is calculated by Euclidean Algorithm
// lcm = m * n / gcd(m,n)
template <typename T = int>
T gcd(T a, T b) {
    if (a < b)
        return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template <typename T = int>
T lcm(T m, T n) {
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main() {
    ll a, b;
    cin >> a >> b;
    set<ll> faca = factors(a);
    set<ll> facb = factors(b);
    set<ll> gcds;
    for (auto &fa : faca) {
        if (facb.count(fa) == 1)
            gcds.insert(fa);
    }
    vl ret;
    gcds.erase(1);
    ret.push_back(1);
    for (auto &g : gcds) {
        bool ok = true;
        for (auto &r : ret) {
            if (gcd(r, g) != 1) {
                ok = false;
                break;
            }
        }
        if (ok)
            ret.push_back(g);
    }
    cout << ret.size() << "\n";
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt(), b = sc.nextInt();
if(a<b){System.out.println("a < b");}
else if(a>b){System.out.println("a > b");}
else{System.out.println("a == b");}
}
}



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

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

  vector<int> a(n);

  int count = 0;
  int total = 0;

  for(int i=0; i<n; i++){
    cin >> a.at(i);
    total += a.at(i);
  }

  float lim = (float)total /4/(float)m ;

  for(int i=0; i<n; i++){
    if((float)a.at(i) < lim){
    }else{
      count++;
    }
  }

  if(count >= m){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl; 
  }

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   string s, t, ans = "No";
   cin >> s >> t;
   int l = s.length();
   for (int offset = 0; offset < l; offset++)
   {
      for (int i = 0; i < l; i++)
      {
         if (s[i] != t[(i + offset) % l])
            break;
         if (i == l - 1)
            ans = "Yes";
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,m,n,l;
    cin>>m>>n;
    int ans=0;
    ans+=(m*(m-1))/2;
    ans+=(n*(n-1))/2;
    cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int n,x;
    int hoge=0;
    int ans=0;
    cin>>n>>x;
    vector<int> m(n);
    for(int i=0;i<n;i++){
        cin>>m[i];
        hoge += m[i];
        ans++;
    }
    int min=m[0];
    for(int i=1;i<n;i++){
        if(m[i]<min){
            min = m[i];
        }
    }
    hoge = x-hoge;
    while(1){
        hoge -= min;
        if(hoge<0){
            break;
        }
        ans++;
    } 
    cout<<ans<<endl;  
    return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String[] params = in.nextLine().split( " " );
        int n = Integer.parseInt( params[0] );
        int m = Integer.parseInt( params[1] );

        boolean[] acs = new boolean[n];
        int[] was = new int[n];
        int acCount = 0;
        int waCount = 0;

        for( int i = 0 ; i < m ; i++ ){

            params = in.nextLine().split( " " );
            int number = Integer.parseInt( params[0] );
            String result = params[1];

            if( !acs[number-1] ){
                if( "WA".equals( result ) ){
                    was[number-1]++;
                }
                if( "AC".equals( result ) ){
                    acs[number-1] = true;
                    acCount++;
                    waCount += was[number-1];
                }
            }

        }

        System.out.println( "" + acCount + " " + waCount );

    }

}


Measured memory_bytes: 103776
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
    var lines = chunk.toString().split(' ');
    var x =lines;
var men = x[0] * x[1];
var syu = x[0]*2 + x[1]*2;
console.log(men +" "+syu);
 
});

Measured memory_bytes: 7644
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1e9;
#define MOD 1e9+7;
#define INF64 1e18;

#define F first
#define S second


using namespace std;

int main() {

	SINT32 N = 0;
	SINT8 S[11];
	SINT64 ANS = 0;

	cin >> N;

	vector<SINT64> DATA(5);
	
	rep(i,0,N) {
		cin >> S;
		if (S[0] == 'M') {
			DATA[0]++;
		} else if (S[0] == 'A') {
			DATA[1]++;
		} else if (S[0] == 'R') {
			DATA[2]++;
		} else if (S[0] == 'C') {
			DATA[3]++;
		} else if (S[0] == 'H') {
			DATA[4]++;
		} else {

		}
	}


	ANS += DATA[0] * DATA[1] * DATA[2];
	ANS += DATA[0] * DATA[1] * DATA[3];
	ANS += DATA[0] * DATA[1] * DATA[4];
	ANS += DATA[0] * DATA[2] * DATA[3];
	ANS += DATA[0] * DATA[2] * DATA[4];
	ANS += DATA[0] * DATA[3] * DATA[4];
	ANS += DATA[1] * DATA[2] * DATA[3];
	ANS += DATA[1] * DATA[2] * DATA[4];
	ANS += DATA[1] * DATA[3] * DATA[4];
	ANS += DATA[2] * DATA[3] * DATA[4];

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

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

namespace ALDS1_3_A
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> lstIn = Console.ReadLine().Split(' ').ToList();
            Stack<int> stack = new Stack<int>();

            foreach (string item in lstIn)
            {
                switch (item)
                {
                    case "+":
                        stack.Push(stack.Pop() + stack.Pop());
                        break;
                    case "-":
                        stack.Push( - stack.Pop() + stack.Pop());
                        break;
                    case "*":
                        stack.Push(stack.Pop() * stack.Pop());
                        break;
                    default:
                        stack.Push(int.Parse(item));
                        break;
                }
            }
            Console.WriteLine(stack.Pop());
            Console.ReadLine();
            
        }
    }
}



Measured memory_bytes: 18720
#include<bits/stdc++.h>
using namespace std;
#define ll      long long int
#define pii     pair<ll,ll>
#define vi      vector<ll>
#define mp      make_pair
#define pb      push_back
#define F       first
#define S       second
#define pf(n)   printf("%lld\n",n)
#define sf(n)   scanf("%lld",&n)
#define fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)  x.begin(),x.end()
#define ms(n,i) memset(n,i,sizeof n)
#define sz(x)   (ll)x.size()
#define pi      3.141592653589793238
#define hell    1000000007
#define hell2   1000000009
#define endl    '\n'
#define inf     1e18
#define N       100005

int main()
{
    ll n,i,j,k;
    cin>>n;
    ll a[n][3],f[n][2];
    for(i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    ll dp[n][3];
    ms(dp,0);
    dp[0][0]=a[0][0],dp[0][1]=a[0][1],dp[0][2]=a[0][2];
    for(i=1;i<n;i++){
        for(j=0;j<3;j++){
            for(k=0;k<3;k++){
                if(j==k)continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
            }
        }
    }
    ll ans=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main{
    
    static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int d = Integer.parseInt(sc.next());
        
        int[] c = new int[26];
        for(int i=0; i<26; i++){
            c[i] = Integer.parseInt(sc.next());
        }
        
        int[][] s = new int[d][26];
        for(int i=0; i<d; i++){
            for(int j=0; j<26; j++){
                s[i][j] = Integer.parseInt(sc.next());
            }
        }
        
        int[] t = new int[d];
        for(int i=0; i<d; i++){
            t[i] = Integer.parseInt(sc.next());
        }
        
        int[] lastday = new int[26];
        
        long score = 0;
        for(int day=1; day<=d; day++){
            int contest = t[day-1]-1;
            score += s[day-1][contest];
            lastday[contest] = day;
            for(int j=0; j<26; j++){
                score -= c[j] * (day-lastday[j]);
            }
            
            System.out.println(score);
        }
        
    }
    
}


Measured memory_bytes: 41876
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	string s;
	cin >> s;
	int ans;
	if (s == "SUN")ans = 7;
	else if (s == "MON")ans = 6; 
	else if (s == "TUE")ans = 5; 
	else if (s == "WED")ans = 4; 
	else if (s == "THU")ans = 3; 
	else if (s == "FRI")ans = 2; 
	else if (s == "SAT")ans = 1;
	cout << ans << endl;
}
int main() {
	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll H, W; cin >> H >> W;
	char c[100][100];
	rep(i, 0, H) {
		rep(j, 0, W) {
			cin >> c[i][j];
		}
	}
	rep(j, 0, W + 2) {
		cout << '#';
	}
	cout << endl;
	rep(i, 0, H) {
		cout << '#';
		rep(j, 0, W) {
			cout << c[i][j];
		}
		cout << '#';
		cout << endl;
	}
	rep(j, 0, W + 2) {
		cout << '#';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, m;
    scan(n, m);

    auto cnt = new int[](n);
    cnt[] = 1;
    auto canRed = new bool[](n);
    canRed[0] = 1;

    foreach (i ; 0 .. m) {
        int xi, yi;
        scan(xi, yi);
        xi--, yi--;

        if (canRed[xi]) {
            canRed[yi] = true;
        }

        cnt[xi]--;
        cnt[yi]++;

        if (cnt[xi] == 0) {
            canRed[xi] = false;
        }

        debug {
            writefln("cnt: %(%s %)", cnt);
            writefln("red: %(%b %)", canRed);
        }
    }

    int ans = canRed.count!"a".to!int;

    writeln(ans);
}










void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 3580
# coding: utf-8
# Your code here!
a,b,c,d=map(int,input())
flg=0
p=[1,-1]

for i in range(2):
    for j in range(2):
        for k in range(2):
            if a+p[i]*b+p[j]*c+p[k]*d==7:
                if p[i]>0:
                    p1="+"
                else:
                    p1="-"
                    
                if p[j]>0:
                    p2="+"
                else:
                    p2="-"
                    
                if p[k]>0:
                    p3="+"
                else:
                    p3="-"
                
                
                print("%d%s%d%s%d%s%d=7"%(a,p1,b,p2,c,p3,d))
                exit()
    

Measured memory_bytes: 3064