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

int main(void){
	int W,H;
	char room[20][20];
	int i,j,k;
	int count;
	scanf("%d %d",&W,&H);
	while(!(W==0&&H==0)){
		for(i=0;i<H;i++){
			scanf("%s",room[i]);
		}
		for(i=0;i<W*H;i++){
			for(j=1;j<H;j++){
				for(k=0;k<W;k++){
					if(room[j][k]!='#' && room[j-1][k]=='@'){
						room[j][k]='@';
					}
				}
			}
			for(j=0;j<H;j++){
				for(k=1;k<W;k++){
					if(room[j][k]!='#' && room[j][k-1]=='@'){
						room[j][k]='@';
					}
				}
			}
			for(j=0;j<H-1;j++){
				for(k=0;k<W;k++){
					if(room[j][k]!='#' && room[j+1][k]=='@'){
						room[j][k]='@';
					}
				}
			}
			for(j=0;j<H;j++){
				for(k=0;k<W-1;k++){
					if(room[j][k]!='#' && room[j][k+1]=='@'){
						room[j][k]='@';
					}
				}
			}
		}
		count=0;
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(room[i][j]=='@'){
					count++;
				}
			}
		}
		printf("%d\n",count);
		scanf("%d %d", &W,&H);
	}
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>tr;

P p[300000];
int c[4][300000];
ll po[300000];

int main(){
	int n;scanf("%d",&n);
	po[0]=1;for(int i=1;i<n;i++)po[i]=(po[i-1]*2)%MOD;
	rep(i,n){
		scanf("%d%d",&p[i].first,&p[i].second);
	}
	sort(p,p+n);
	tr.clear();
	rep(i,n){
		c[0][i]=tr.order_of_key(p[i].second);
		c[1][i]=i-c[0][i];
		tr.insert(p[i].second);
	}
	tr.clear();
	for(int i=n-1;i>=0;i--){
		c[3][i]=tr.order_of_key(p[i].second);
		c[2][i]=n-i-1-c[3][i];
		tr.insert(p[i].second);
	}
	ll ans=0;
	rep(i,n){
		ll U=po[n-1];
		rep(j,4){
			(U+=MOD-po[n-1-c[j][i]-c[(j+1)%4][i]])%=MOD;
			(U+=po[c[j][i]])%=MOD;
		}
		(U+=MOD-1)%=MOD;
		(ans+=po[n-1]+U)%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  vector<P> cm(m);
  for(int i=0; i<m; ++i) cin >> cm[i].second >> cm[i].first;
  sort(an.begin(),an.end());
  sort(cm.begin(),cm.end());
  ll ans = 0;
  for(int i=0; i<n; ++i){
    int s1 = an.size()-1;
    int s2 = cm.size()-1;
    if(s2 == -1 || an[s1] >= cm[s2].first){
      ans += an[s1];
      an.pop_back();
    }else{
      ans += cm[s2].first;
      --cm[s2].second;
      if(cm[s2].second <=0) cm.pop_back();
    }
  }
  cout << ans << endl;
}

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

C = [[0] * 10 for i in range(10)]

for n in range(1, N+1):
    i = int(str(n)[0])
    j = int(str(n)[-1])
    C[i][j] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += C[i][j]*C[j][i]
print(ans)


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

// @@ !! LIM()

// ad-hoc power function
template<typename T, typename Op>
T ah_power(T a, ll b, const T& unit_t, Op op) {
  T two_pow = a;
  T ret = unit_t;
  while (b > 0) {
    if (b & 1LL) ret = op(ret, two_pow);
    two_pow = op(two_pow, two_pow);
    b >>= 1;
  }
  return ret;
}


vector<ll> comp(const vector<ll>& v1, const vector<ll>& v2) {
  vector<ll> ret(v1.size());
  for (ll i = 0; i < (ll)v1.size(); i++) ret.at(i) = v2.at(v1.at(i));
  return ret;
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector vec(N+1, 0LL);
  for (ll i = 1; i <= N; i++) {
    cin >> vec.at(i);
  }
  vector unit(N+1, 0LL);
  iota(unit.begin(), unit.end(), 0);
  auto fin = ah_power(vec, K, unit, comp);
  cout << fin.at(1) << endl;

  return 0;
}



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

int main()
{
   int n,m;
   cin>>n>>m;
   while(m--){
       int x;cin>>x;
       n-=x;
   }
   if(n<0){
       cout<<"-1";
   }else{
       cout<<n;
   }
   return 0;
}

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

template<typename T, typename E, typename F, typename G, typename H>
class LazySegmentTree {
  int n, height;
  F f; G g; H h; const T ti; const E ei;
  vector<T> dat; vector<E> laz; vector<int> highest;

  void propagate(int k) {
    if(laz[k] != ei) {
      laz[2*k] = h(laz[2*k],laz[k]); laz[2*k+1] = h(laz[2*k+1],laz[k]);
      dat[k] = g(dat[k],laz[k],n/highest[k]);
      laz[k] = ei;
    }
  }
  inline void recalc(int k) {
    while(k >>= 1) dat[k] = f(g(dat[2*k],laz[2*k],n/highest[2*k]),g(dat[2*k+1],laz[2*k+1],n/highest[2*k+1]));
  }
  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }
public:
  LazySegmentTree(int _n, F f, G g, H h, T ti, E ei): f(f), g(g), h(h), ti(ti), ei(ei) {
    n = 1; height = 0;
    while(n < _n) n <<= 1, height++;
    dat.assign(2*n,ti); laz.assign(2*n,ei); highest.assign(2*n,0);
    int c = 1;
    for(int i = 1; i < 2*n; i++) {
      if(c*2 <= i) c <<= 1;
      highest[i] = c;
    }
  }
  void set(int k, T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int a, int b, const E x) {
    thrust(a += n); thrust(b += n-1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l],x), ++l;
      if(r & 1) --r, laz[r] = h(laz[r],x);
    }
    recalc(a); recalc(b);
  }
  T query(int a, int b) {
    thrust(a += n); thrust(b += n-1);
    T l = ti, r = ti; b++;
    while(a < b) {
      if(a & 1) l = f(l,g(dat[a],laz[a],n/highest[a])), a++;
      if(b & 1) b--, r = f(g(dat[b],laz[b],n/highest[b]),r);
      a >>= 1; b >>= 1;
    }
    return f(l,r);
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  auto f = [](ll a, ll b){return a+b;};
  auto g = [](ll a, ll b, int l){return b == INF ? a : b*l;};
  auto h = [&](ll a, ll b) {return b;};
  LazySegmentTree<ll,ll,decltype(f),decltype(g),decltype(h)> lst(n,f,g,h,0,INF);
  rep(i,n) lst.set(i,((ll)1<<31)-1);
  lst.build();
  vector<ll> ans;
  rep(i,q) {
    int t;
    cin >> t;
    if(t == 0) {
      int l, r; ll x;
      cin >> l >> r >> x;
      lst.update(l,r+1,x);
    } else {
      int p;
      cin >> p;
      ans.push_back(lst.query(p,p+1));
    }
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


Measured memory_bytes: 8960
import sys
sys.setrecursionlimit(10**5)
def dfs(now):
  if v[now]:return v[now]
  res=1
  for to in e[now]:
    res=max(res,dfs(to)+1)
  v[now]=res
  return res
n,m=map(int,input().split())
e=[[]for _ in range(n+1)]
for i in range(m):
  x,y=map(int,input().split())
  e[x]+=[y]
v=[0]*(n+1)
v[0]=1
ans=0
for i in range(n+1):
  ans=max(ans,dfs(i))
print(ans-1)

Measured memory_bytes: 124468
//given n integers and an integer m such that n>m then there exits a pair
//(a-b) such that (a-b)%m==0

#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
const ll M=1000000007;
void solve(){
 int n;
 cin>>n;
 if(n>=30)cout<<"Yes";
 else cout<<"No";
}

int main(){
 int t=1;
 //cin>>t;
 while(t--){
        solve();
        cout<<endl;
 }
}


Measured memory_bytes: 3636
//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 200005
#define oo 1000000007

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, T, a[maxN];
map<int, int> m;

int main () {
    //freopen("input.txt", "r", stdin);

    scanf("%d%d", &n, &T);
    fto(i, 0, n-1) scanf("%d", &a[i]);

    int x = 0, minA = oo;
    fto(i, 0, n-1) {
        x = max(x, a[i]-minA);
        minA = min(minA, a[i]);
    }

    ll ans = 0;
    fto(i, 0, n-1) {
        ans += m[a[i]-x];
        ++m[a[i]];
    }

    cout << ans;


    return 0;
}


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


const int N=1e6,OO = 0x3f3f3f3f;
int d()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
long long lld()
{
    long long ret;
    scanf("%lld", &ret);
    return ret;
}
vector<int>v[N];
int main(){
    string s,s1,s2;
    cin>>s>>s1>>s2;
    cout<<s[0]<<s1[1]<<s2[2]<<endl;
}


Measured memory_bytes: 23680
//
// Created by Kiran Chavhan on 05/07/2020.
//

#include<bits/stdc++.h>

#define int long long
#define MOD 1000000007
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    if(n%1000==0)cout<<0;
    else {
        int k=n/1000;
        k=(k+1)*1000;
        cout<<k-n;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    using P = pair<int, int>;
    vector<P> v(n);
    rep(i, n){
        int a;
        cin >> v[i].first;
        v[i].second = i;
    }
    sort(all(v));
    rep(i, n){
        cout << v[i].second+1 << endl;
    }
}

Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
    int a1,a2,a3,s;
    scanf("%d %d %d",&a1,&a2,&a3);
    s=a1+a2+a3;
    if(s>=22)
        printf("bust\n");
    else
        printf("win\n");
    return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 10000000;
using namespace std;
typedef long long  ll;
/** Problem0112 : A Milk Shop **/
int main()
{
	vector<ll> c;
	ll t, n, ans;

	while (cin>>n, n!=0) {
		c.clear();
		ans=0;
		rep(i, n) {
			cin >> t;
			c.push_back(t);
		}
		sort(c.begin(), c.end());
		rep(i, n) {
			ans += c[i]*(n-i-1);
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1340
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		char ans = sc.next().charAt(0);
		if(ans < 'a') {
			System.out.println("A");
		}else{
			System.out.println("a");
		}
	}
}




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

using namespace std;

typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
const int MOD = 998244353;
void add (int &a, int b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
    if (a < 0) a += MOD;
}
int mult (int a, int b) {
    return (1ll * a * b % MOD);
}

int lgput (int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1)
            ans = mult (ans, a);
        a = mult (a, a);
        b /= 2;
    }
    return ans;
}
const int N = 2e5;
int f[1 + N], invf[1 + N];
void prec () {
    f[0] = 1;
    for (int i = 1; i <= N; i++)
        f[i] = mult (f[i - 1], i);
    invf[N] = lgput (f[N], MOD - 2);
    for (int i = N - 1; i >= 0; i--)
        invf[i] = mult (invf[i + 1], i + 1);
}

int comb (int n, int k) {
    return mult (f[n], mult (invf[k], invf[n - k]));
}

int main() {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int n, m, k;
    cin >> n >> m >> k;
    int ans = 0;
    prec ();
    for (int c = 0; c <= k; c++) {
        int cur = mult (m, lgput (m - 1, n - c - 1));
        cur = mult (cur, comb (n - 1, c));
        add (ans, cur);
    }
    cout << ans << "\n";
    return 0;
}


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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	int cnt = 0;
	cin >> s;
	for(int i = 0;i < (s.length()+1)/2; ++i){
		cnt += s[i] != s[s.length() - 1 - i];
	}
	cout << cnt << '\n';
}


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

using namespace std;

#define int long long

signed main()
{
    int n, x, y;
    cin >> n >> x >> y;
    --x; --y;
    vector<vector<int>> g(n);
    for(int i = 0; i < n - 1; ++i)
    {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);
    vector<vector<int>> dist(n);
    for(int i = 0; i < n; ++i)
    {
        vector<int> d(n, 1e9);
        d[i] = 0;
        deque<int> q;
        q.push_front(i);
        while(!q.empty())
        {
            int v = q.front();
            q.pop_front();
            for(int u : g[v])
            {
                if (d[u] > d[v] + 1)
                {
                    d[u] = d[v] + 1;
                    q.push_back(u);
                }
            }
        }
        dist[i] = d;
    }
    vector<vector<int>> d1(n, vector<int> (n, 0));
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            ++d1[i][dist[i][j]];
        }
    }
    for(int k = 1; k < n; ++k)
    {
        long long ans = 0;
        for(int i = 0; i < n; ++i)
        {
            ans += d1[i][k];
        }
        cout << ans / 2 << '\n';
    }
}

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

using namespace std;

int main()
{
    int n, m;
    cin>>n;
    if(n%4==0||n%7==0)
    {
        cout<<"Yes"<<endl;

    }
    else
    {
        for(int i=1; i<=100; i++)
        {
            for(int j=1; j<=100; j++)
            {
                if(i*4+j*7==n)
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
        cout<<"No"<<endl;
    }
    return 0;
}



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

using namespace std;

const int N=2e5+10;

struct Edge{ int to,next; }way[N<<1];

int n,X,Y,a[N],b[N],tot,num[N],dep[N],dis[N],f[N];
bool t[N],vis[N];

void Build(int a,int b) { way[++tot]=(Edge){b,num[a]}; num[a]=tot; }

void EdgeClear()
{
	tot=0;
	for (int i=1;i<=n;++i) num[i]=0;
}

void Init()
{
	scanf("%d%d%d",&n,&X,&Y);
	for (int i=2;i<=n;++i)
		scanf("%d%d",&a[i],&b[i]);
	int x,y;
	for (int i=2;i<=n;++i)
	{
		scanf("%d%d",&x,&y);
		Build(x,y); Build(y,x);
	}
}

void Dfs(int x,int fa)
{
	dep[x]=dep[fa]+1; f[x]=fa;
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (v==fa) continue;
		Dfs(v,x);
	}
}

queue<int>Q;
void Bfs(int s)
{
	dis[s]=0; Q.push(s); vis[s]=1;
	while (!Q.empty())
	{
		int u=Q.front(); Q.pop();	
		for (int i=num[u];i;i=way[i].next)
		{
			int v=way[i].to;
			if (vis[v]) continue;
			dis[v]=dis[u]+1;
			if (dis[v]<dep[v]) { vis[v]=1; Q.push(v); }
		}
	}
}

void Solve()
{
	dep[0]=-1; Dfs(Y,0);
	
	EdgeClear();
	for (int i=2;i<=n;++i)
	{
		int x=a[i],y=b[i];
		if (dep[x]>dep[y]) swap(x,y);
		
		bool fl=1;
		if (f[y]==x || f[f[y]]==x || f[x]==f[y]) fl=0;else fl=1;
		
		if (fl) t[x]=t[y]=1;
		else Build(x,y),Build(y,x);
	}
	
	Bfs(X);
	
	int ans=0;
	for (int i=1;i<=n;++i)
	{
		if (t[i] && vis[i]) { printf("-1\n"); return ; }
		if (vis[i]) ans=max(ans,dep[i]);
	}
	printf("%d\n",ans<<1);
}

int main()
{
	Init();
	Solve();
	return 0;
}


Measured memory_bytes: 14080
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

typedef long long ll;

inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0' || '9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x*f;
}

const int N=2e6+9;
ll n,a[N],ans;

inline ll calc(int mid)
{
	return abs(a[mid]-(a[n]-a[mid]));
}

int main()
{
	n=read();
	a[0]=0;
	for(int i=1;i<=n;i++)
		a[i]=read()+a[i-1];

	ans=1e18;
	for(int i=1;i<n;i++)
		ans=min(ans,calc(i));

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int x = int.Parse(input[0]);
		int y = int.Parse(input[1]);
		bool exists = false;
		if(y%2==0 && 2*x <= y && y <= 4*x) exists = true;
		Console.WriteLine(exists ? "Yes" : "No");		

	}
}


Measured memory_bytes: 27524
N=int(input())
A=input().split()
x=0
for i in range(N):
  if int(A[i])%2==0:
    if int(A[i])%5==0 or int(A[i])%3==0:
      x+=1
  else:
    x+=1
if x==N:
  print('APPROVED')
else:
  print('DENIED')


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

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

    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int A=0, B=0;
    rep(i, N) {
        if (i%2==0) A += a[i];
        else B += a[i];
    }
    cout << A-B << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
dic = {"AC":0, "WA":0, "TLE":0, "RE":0}
for i in range(n):
  s = input()
  dic[s] += 1
print("AC x " + str(dic["AC"]))
print("WA x " + str(dic["WA"]))
print("TLE x " + str(dic["TLE"]))
print("RE x " + str(dic["RE"]))

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, tmp, ans =0;
	map<int,int> m;
	cin >> n;
	REP(i, 0, n){
		cin >> tmp;
		++m[tmp];
	}
	for(auto it:m) 
		ans += it.second % 2;
	
	cout << ans;

}


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

int main() {
    int N, K;
    string S, T;
    cin >> S;
    N = (int)S.size();
    cin >> K;
    T = S;
    reverse(T.begin(), T.end());
    
    vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(N+1, vector<int>(K+1, 0)));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            bool same;
            if (S[i-1] == T[j-1]) same = true;
            else same = false;
            if (same) {
                for (int k = 0; k <= K; k++) {
                    dp[i][j][k] = max(max(dp[i-1][j][k], dp[i][j-1][k]), dp[i-1][j-1][k]+1);
                }
            }else {
                for (int k = 0; k <= K; k++) {
                    dp[i][j][k] = max(dp[i-1][j][k], dp[i][j-1][k]);
                    if (k > 0) dp[i][j][k] = max(dp[i][j][k], dp[i-1][j-1][k-1]+1);
                }
            }
        }
    }
    int ans = 0;
    if (N%2 == 0) {
        for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= K; j++) {
                ans = max(ans, 2*dp[i][N-i][j]);
                if (i < N) ans = max(ans, 2*dp[i][N-1-i][j]+1);
            }
        }
    }else {
        for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= K; j++) {
                ans = max(ans, 2*dp[i][N-i][j]);
                if (i < N) ans = max(ans, 2*dp[i][N-1-i][j]+1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 110336
my $N = <STDIN>;
chomp($N);
my $S = <STDIN>;
chomp($S);
my @A;
my $lw = '';
foreach my $w ( split("", $S) ) {
    if ( $w eq $lw ) {
    } else {
        push(@A, $w);
        $lw = $w;
    }
}
my $ans = @A;
print $ans;

Measured memory_bytes: 17024
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n,pos;
vector<int> pre,in,post;

void rec(int l,int r) {
    if(l>=r) return;
    int root=pre[pos++];
    int m=distance(in.begin(),find(all(in),root));
    rec(l,m);
    rec(m+1,r);
    post.pb(root);
}
void solve() {
    pos=0;
    rec(0,pre.size());
    rep(i,n) printf("%d%c",post[i],i==n-1?'\n':' ');
}


int main() {
    int k;
    cin>>n;
    rep(i,n) {
        cin>>k;
        pre.pb(k);
    }
    rep(i,n) {
        cin>>k;
        in.pb(k);
    }
    solve();
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;

int main(){
    int N, M , R;
    cin >> N >> M >> R;
    vi r(R);
    rep(i, R){
        int va;
        cin >> va;
        r[i] = va-1;
    }
    sort(r.begin(), r.end());

    int G[N][N];
    rep(i, N)rep(j, N)G[i][j] = i == j ? 0 : INF;
    int a, b, c;
    rep(i, M){
        cin >> a >> b >> c;
        a--; b--;
        G[a][b] = c;
        G[b][a] = c;
    }

    rep(k, N)rep(i, N)rep(j, N)
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
    
    int ans = INF, sum = 0;
    while(next_permutation(r.begin(), r.end())){
        sum = 0;
        rep(i, R - 1)
            sum += G[r[i]][r[i + 1]];
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vint;

int n,m,vi[2010],da[2010],vo[2010];
double prob[2010],probsum[2010];
double vires[2010],dares[2010],vores[2010];

void calc(int stat[],int point,double res[]){
	rep(i,m+1){
		int me=stat[0]*i;
		double dp[4],worst=1;
		dp[0]=1;
		dp[1]=dp[2]=0;
		rep2(j,1,n){
			int time = (me+stat[j]-1)/stat[j];
			double lose;
			if(time > m) lose = 0;
			else lose = 1 - probsum[time];
			worst *= lose;
			for(int k=2;k>=0;k--){
				dp[k+1] += dp[k]*lose;
				dp[k] -= dp[k]*lose;
			}
		}
		res[i]=point*(dp[0]+dp[1]+dp[2])-worst;
	}
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>n>>m;
	rep(i,n)cin>>vi[i]>>da[i]>>vo[i];
	
	prob[0]=1;
	rep(i,m){
		for(int j=i;j>=0;j--){
			prob[j+1] += prob[j]/3;
			prob[j] -= prob[j]/3;
		}
	}
	probsum[0]=0;
	rep(i,m+1){
		probsum[i+1]=probsum[i]+prob[i];
	}
	
	calc(vi,5,vires);
	calc(da,3,dares);
	calc(vo,2,vores);
	
	double ans=-INF;
	rep(i,m+1)rep(j,m-i+1){
		int k=m-i-j;
		ans=max(ans,vires[i]+dares[j]+vores[k]);
	}
	cout<<fixed<<setprecision(16)<<ans<<endl;
}

Measured memory_bytes: 1368
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    int ans = 0;
    REP(maski,1<<h) REP(maskj,1<<w){
        int cnt = 0;
        REP(i,h) REP(j,w){
            if (((maski >> i) & 1) == 0) continue;
            if (((maskj >> j) & 1) == 0) continue;
            cnt += (s[i][j] == '#');
        }
        if (cnt == k) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
fn read<T: std::str::FromStr>() -> T {
    let mut s  = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main(){
    for i in 1 ..{
        let x:i32 = read();
        if x == 0 { break }
        println!("Case {}: {}", i , x)
    }
}



Measured memory_bytes: 5036
N,M = map(int,input().split())
H = list(map(int,input().split()))
H = [0] + H
Tree = [0] + [1]*N
for _ in range(M):
  A,B = map(int,input().split())
  if H[A] > H[B]:
    Tree[B] = 0
  elif H[A] == H[B]:
    Tree[A]=0
    Tree[B]=0
  else:
    Tree[A] = 0
print(sum(Tree))

Measured memory_bytes: 20144
// AOJ 0526: Boat Travel
// 2017.9.1 bal4u@uu
// 2017.12.2

#include <stdio.h>
#include <string.h>

#define INF 0x1fffffff
#define N 105			// >= 100+2
#define MAX 11000		// >= N*N

typedef struct { int t, node; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int n, int t)
{
	int i, min;
	QUE qt;
	i = qsize++;
	que[i].node = n, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		i = min;
	}
}

typedef struct { int to[N], t[N]; } TBL;
TBL tbl[N];
int len[N];
char mk[N];

char buf[50], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int search(int start, int goal)
{
	int i, s, t, e;

	qsize = 0;
	memset(mk, 0, sizeof(mk));
	enq(start, 0);
	while (qsize) {
		s = que[0].node, t = que[0].t, deq();
		if (s == goal) return t;
		if (mk[s]) continue;
		mk[s] = 1;
		for (i = 0; i < len[s]; i++) {
			e = tbl[s].to[i];
			if (mk[e]) continue;
			enq(e, t + tbl[s].t[i]); 
		}
	}
	return -1;
}

int main()
{
	int n, k, a, b, e, t;

	while (fgets(p=buf, 50, stdin) && *p != '0') {
		n = getint(), k = getint();
		memset(len, 0, sizeof(len));
		while (k-- > 0) {
			fgets(p=buf, 50, stdin);
			if (*p & 1) {
				p += 2;
				a = getint(), b = getint(), e = getint();
				t = len[a], tbl[a].to[t] = b, tbl[a].t[t] = e, len[a]++;
				t = len[b], tbl[b].to[t] = a, tbl[b].t[t] = e, len[b]++;
			} else {
				p += 2;
				a = getint(), b = getint();
				printf("%d\n", search(a, b));
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1852
#include<cstdio>
#include<algorithm>

int n;
int ans=1;

int main()
{
	int mn;
	scanf("%d%d",&n,&mn);
	for(int i=1;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		if(a<mn) ans++;
		mn=std::min(a,mn);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        int[] a = new int[n];
        int[] b = new int[n];
        HashMap<Integer,Integer> h = new HashMap<>();
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        long ans = 0;
        for(int i=0; i<n; i++){
            b[i] = a[i] + i;
            h.put(b[i], h.getOrDefault(b[i], 0)+1);
            ans += h.getOrDefault(i-a[i], 0);
        }
        
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 56888
import collections
import heapq
n = int(raw_input())
ais = [0] + map(int, raw_input().split()) 
#print ais
res = [0 for __ in range(n +1)]
for u in range(n, 0, -1):
	c = u*2
	cumul = 0
	while(c <= n):
		cumul += res[c]
		c += u
	if ais[u] != (cumul % 2): 
		res[u] = 1
s = sum(res)
print s
if s:
	print ' '.join([str(i) for i in range(len(res)) if res[i] == 1])

Measured memory_bytes: 56408
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int x, y;

int main() {
	cin >> x >> y;
	if (x == 2 || y == 2) { cout << "No" << endl; return 0; }
	int a[4] = { 4,6,9,11 };
	bool flag = 0;
	for (int i = 0; i < 4; i++) {
		if (x == a[i])flag = 1;
	}
	bool flagb = 0;
	for (int i = 0; i < 4; i++) {
		if (y == a[i])flagb = 1;
	}
	if ((flag == 1 && flagb == 1) || (flag == 0 && flagb == 0)) {
		cout << "Yes" << endl;
		return 0;
	}
	else {
		cout << "No" << endl;
	}
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int m, k; cin >> m >> k;
  int s = 1<<m;
  if (k>=s) {
    cout << -1 << endl;
    return 0;
  }

  if (m==1) {
    if (k==0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }

  deque<int> que;
  que.push_back(k);
  for(int i=0; i<s; i++) {
    if (i==k) continue;
    que.push_back(i);
    que.push_front(i);
  }
  que.push_back(k);
  for(auto e: que) {
    cout << e << ' ';
  }
  cout << endl;
}

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

int main()
{
  std::string s;
  std::cin >> s;
  
  const struct word_def
  {
    std::string str;
    int length;
  } words[4] =
  {
    {"dream", 5},
    {"dreamer", 7},
    {"erase", 5},
    {"eraser", 6},
  };
  
  auto r_itr = s.rbegin();
  bool found = true;
  while(r_itr != s.rend() && found)
  {
    found = false;
    for(auto w : words)
    {
      if(std::equal(w.str.rbegin(), w.str.rend(), r_itr))
      {
        std::advance(r_itr, w.length);
        found = true;
        break;
      }
    }
  }
  
  printf("%s", (r_itr != s.rend()) ? "NO" : "YES");
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

uintmax_t combination(unsigned int n, unsigned int r)
{
    if (r * 2 > n)
        r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor = 1;
    for (unsigned int i = 1; i <= r; ++i)
    {
        dividend *= (n - i + 1);
        divisor *= i;
    }
    return dividend / divisor;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    int X;
    cin >> X;
    if(X <= 599){
        cout << 8 << endl;
    }
    else if(X <=799){
        cout << 7<< endl;
    }
    else if (X <= 999)
    {
        cout << 6 << endl;
    }
    else if (X <= 1199)
    {
        cout << 5 << endl;
    }
    else if (X <= 1399)
    {
        cout << 4<< endl;
    }
    else if (X <= 1599)
    {
        cout << 3 << endl;
    }
    else if (X <= 1799)
    {
        cout << 2 << endl;
    }
    else if (X <= 1999)
    {
        cout <<1 << endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int n;

bool check(int pos, VI &b, VI &v)
{
    int cur = 0;
    rep(i, n)
    {
        cur ^= v[i];
    }
    rep(i, n)
    {
        cur ^= v[i];
        if (((cur >> pos) & 1) != b[i])
        {
            return false;
        }
        cur ^= v[i];
    }
    return true;
}

int main()
{
    cin >> n;
    VI v(n);
    rep(i, n) cin >> v[i];
    VI b(n, 0);
    VI ans(n, 0);
    rep(i, 30)
    {
        b[0] = 0;
        rep(j, 1, n)
        {
            b[j] = (((v[j] ^ v[0]) >> i) & 1);
        }
        if (check(i, b, v) == false)
        {
            rep(j, n)
            {
                b[j] ^= 1;
            }
            assert(check(i, b, v));
        }
        rep(j, n)
        {
            ans[j] |= b[j] << i;
        }
    }
    int cur = 0;
    rep(i, n)
    {
        cur ^= ans[i];
        cout << ans[i] << " ";
    }
    cout << endl;
    rep(i, n)
    {
        //   cerr << (cur ^ ans[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 5548
// 2019/12/04 Tazoe

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

const int INF = 3000;

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

	int WBR[50][3] = { {0} };
	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++){
			char c;
			cin >> c;

			switch(c){
			case 'W':
				WBR[i][0]++;
				break;
			case 'B':
				WBR[i][1]++;
				break;
			case 'R':
				WBR[i][2]++;
				break;
			}
		}
	}
/*
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			cout << WBR[i][j] << ' ';
		}
		cout << endl;
	}
*/

	int DP[51][4];
	for(int j=1; j<=3; j++){
		DP[0][j] = INF;
	}
	for(int i=1; i<=N; i++){
		DP[i][0] = INF;
	}
	DP[0][0] = 0;

	for(int i=1; i<=N; i++){
		for(int j=1; j<=3; j++){
			DP[i][j] = min(DP[i-1][j-1], DP[i-1][j])+(M-WBR[i-1][j-1]);
		}
	}

	cout << DP[N][3] << endl;

	return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>
#include <algorithm>

int main() {
	std::string s;
	std::cin >> s;

	std::reverse(s.begin(), s.end());

	std::int64_t ans = 0;

	std::vector<int> count(2019 + 1);
	int val = 0, dig = 1;
	for (auto&& c : s) {
		int x = c - '0';

		(val += x * dig) %= 2019;
		if (val == 0)
			++ans;

		ans += count[val];

		++count[val];
		dig = (dig * 10) % 2019;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int N, s;
  cin >> N;
  vector<int> V;
  int S = 0;
  for(int i = 0; i < N; ++i){
    cin >> s;
    S += s;
    V.push_back(s);
  }
  sort(V.begin(),V.end());
  int i = 0;
  while((!(S%10)) && i < N){
    if(V[i]%10) S -= V[i];
    ++i;
  }
  if(i == N && !(S%10)) cout << 0 << endl;
  else cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forr(x,n) for(int x = 0; x < n; ++x)
#define pr pair<int,int>
#define ll long long int
const int mod=998244353;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    cout<<ceil(n/2.0);

}


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

using namespace std;

int main()
{
    int N,L;
    cin >> N;
    int sum=0,m=0; 

    for(int i=0; i<N; i++){
        cin >> L;
        m = max(m,L);
        sum += L;
    }

    if(m < sum-m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}

Measured memory_bytes: 3608
#!/usr/bin/env python3
import sys
import numpy as np

def list_prime(max):
    primes = []
    for i in range(1, max):
        if max % i == 0:
            primes.append(i)
        if i >= np.sqrt(max):
            break
    if len(primes) <= 1:
        primes.append(max)
    return primes

def solve(N: int):
    print(len(str(max(int(N / list_prime(N)[-1]), list_prime(N)[-1]))))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14476
h,w=map(int,input().split())
s=[]
for _ in range(h):
    s.append(list(input()))
l=[[0 for x in range(w+2)] for y in range(h+2)]
r=[[0 for x in range(w+2)] for y in range(h+2)]
u=[[0 for x in range(w+2)] for y in range(h+2)]
d=[[0 for x in range(w+2)] for y in range(h+2)]
#l
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i-1][j-1]==".":
            l[i][j]=l[i][j-1]+1
        else:
            l[i][j]=0
#r
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i-1][w-(j-1)-1]==".":
            r[i][w+1-j]=r[i][w+1-j+1]+1
        else:
            r[i][w+1-j]=0
#u
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i-1][j-1]==".":
            u[i][j]=u[i-1][j]+1
        else:
            u[i][j]=0
#d
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[h-(i-1)-1][j-1]==".":
            d[h+1-i][j]=d[h+1-i+1][j]+1
        else:
            d[h+1-i][j]=0
ans=0
for y in range(1,h+1):
    for x in range(1,w+1):
        sum=r[y][x]+l[y][x]+u[y][x]+d[y][x]-3
        if ans<sum:
            ans=sum
print(ans)


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

int main() {
	int a;
	cin >> a;
	int b = int(double(a) / 1.08);
	bool f = false;
	if (int((b - 2) * 1.08) == a) {
		cout << b - 2 << endl;
		return 0;
	}
	if (int((b - 1) * 1.08) == a) {
		cout << b -1 << endl;
		return 0;
	}
	if (int((b + 0) * 1.08) == a) {
		cout << b + 0 << endl;
		return 0;
	}
	if (int((b + 1) * 1.08) == a) {
		cout << b + 1 << endl;
		return 0;
	}
	if (int((b + 2) * 1.08) == a) {
		cout << b+2 << endl;
		return 0;
	}

	cout << ":(" << endl;

}

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

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


void solve(long long N, std::string X){
    ll originalOnes =0;
    for(int i=N-1;i>=0;--i){
        if(X[i] == '1'){
            originalOnes++;
        }
    }
   
    // for(int i=N-1;i>=0;--i){
    //     plusNum*=2;
    //     minusNum*=2;
    //     if(X[i] == '1'){
    //         plusNum++;
    //         minusNum++;
    //     }
    //     plusNum%=(originalOnes+1);
    //     minusNum%=(originalOnes-1);
    // }
     ll plusNum =0;
    ll minusNum = 0;
    for(int i=0;i<N;i++){
        if(X[i] =='1'){
            plusNum+= mod_pow(2ll,N-1-i,originalOnes+1);
             if(originalOnes!=1){
            minusNum+= mod_pow(2ll,N-1-i,originalOnes-1);
             }
        }
        plusNum %= (originalOnes+1);
        if(originalOnes==1){
            minusNum=0;
        }else{
            minusNum %= (originalOnes-1);
        }
        
    }
    // cerr <<"debug=" <<debug << endl;
    // cerr <<"plus=" <<plusNum <<"minusNum =" <<minusNum << endl;
    for(ll i=0;i<N;i++){
        if(X[i] =='0'){
            ll ones = originalOnes+1;
            ll num = plusNum + mod_pow(2ll,N-1-i,ones);
            num%= ones;
            ll ans =1;
            while(num>0){
                num %= __builtin_popcount(num);
                ans++;
            }
            cout << ans << "\n";
        }else{
            if(originalOnes ==1){
                cout << 0 <<"\n";
                continue;
            }
            ll ones = originalOnes-1;
            ll num = minusNum + ones -mod_pow(2ll,N-1-i,ones);
            // cerr <<"pow=" <<mod_pow(2ll,N-1-i,ones)<< endl;
            // cerr <<"i="<<i <<"num=" <<num<<"ones=" <<ones<< endl;
            num%= ones;
            ll ans =1;
            while(num>0){
                num %= __builtin_popcount(num);
                ans++;
            }
            cout << ans << "\n";
            
        }
    }


}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string X;
    std::cin >> X;
    solve(N, X);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep0c(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

int N;
vector<pair<int, int> > G[100010];
bool visited[100010];
int color[100010];

void solve() {
  queue<pair<int, int> > que;
  visited[0] = true;
  color[0] = 0;
  for(const auto& edge : G[0]) {
    que.push(make_pair(edge.first, edge.second%2));
  }
  while(!que.empty()) {
    auto edge = que.front(); que.pop();
    int v = edge.first;
    int w = edge.second;
    if(visited[v]) continue;
    visited[v] = true;
    color[v] = w;
    for(const auto& e : G[v]) {
      que.push(make_pair(e.first, (w+e.second)%2));
    }
  }
  rep(i, N) {
    if(color[i]) printf("1\n");
    else printf("0\n");
  }
}

int main() {
  scanf("%d", &N);
  rep(i, N-1) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    --u;
    --v;
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
  }
  solve();
  return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long a, b, k; cin >> a >> b >> k;
	long long p = min(a, k);
	a -= p;
	k -= p;
	long long q = min(b, k);
	b -= q;
	k -= q;
	cout << a << " " << b << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())

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

    ans = 0

    ans_list = [0] * m

    for i in range(n):
        for j in range(num_list[i][0]):
            ans_list[num_list[i][j+1]-1] += 1
        
    for i in range(m):
        if n == ans_list[i]:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()

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

int main(void)
{
    char b;
    cin >> b;

    if (b == 'A')
        cout << 'T' << endl;
    else if (b == 'T')
        cout << 'A' << endl;
    else if (b == 'C')
        cout << 'G' << endl;
    else if (b == 'G')
        cout << 'C' << endl;
    return (0);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a[4][13],c,d=0,n,e=0,i=0,j=0;
	char b;

	while(i != 4){
		while(j != 13){
			a[i][j] = 0;
			j++;
		}
		j=0;
		i++;
	}
	scanf("%d",&d);
	while(d != e){
		scanf("%s %d",&b,&c);
		if(b == 'S')
			a[0][c-1] = 1;
		if(b == 'H')
			a[1][c-1] = 1;
		if(b == 'C')
			a[2][c-1] = 1;
		if(b == 'D')
			a[3][c-1] = 1;
		e++;
	}
	i = 0; j = 0;
	while(i != 4){
		while(j != 13){
			if(a[i][j] == 0){
				if(i==0)
					printf("S %d\n",j+1);
				if(i==1)
					printf("H %d\n",j+1);
				if(i==2)
					printf("C %d\n",j+1);
				if(i==3)
					printf("D %d\n",j+1);	
			}
			j++;
		}
		j=0;
		i++;	
	}
	return 0;
}

	

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int m=sc.nextInt();
			int f=sc.nextInt();
			int r=sc.nextInt();
			char grade;
			
			if(m==-1&&f==-1&&r==-1) {
				break;
			}
			
			if(m==-1||f==-1) {
				 grade = 'F';
			}else if(m+f>=80) {
				 grade='A';
			}else if(m+f>=65) {
				 grade='B';
			}else if(m+f>=50) {
				 grade='C';
			}else if(m+f>=30&&r>=50) {
				 grade ='C';
			}else if(m+f>=30) {
				 grade='D';
			}else {
				 grade='F';
			}
		System.out.println(grade);	
			
		}
	sc.close();			
	}
	

}




Measured memory_bytes: 26064