akhauriyash/Code-Regression huggingface dataset:
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    // 端からやると連続したkます以外は好きに決められる
    // 連続したkますを固定するとそれ以外は貪欲に取るのが良い
    let mut s1 = vec![0i64; n + 1];
    let mut s2 = vec![0i64; n + 1];
    for i in 0..n {
        s1[i + 1] = s1[i] + a[i];
        s2[i + 1] = s2[i] + max(a[i], 0);
    }

    let mut ans = 0i64;
    for i in 0..n - k + 1 {
        ans = max(ans, s2[i] + s2[n] - s2[i + k] + max(s1[i + k] - s1[i], 0));
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input!{
        a: char
    }
    let s: char;
    if a.is_lowercase(){
        s = 'a';
    }else{
        s = 'A';
    }
    println!("{}", s);
}


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

int main() {
	int n;
	cin >> n;
	vector<int>l(n*2);
	for (int i = 0; i < 2*n; i++)cin >> l.at(i);
	sort(l.begin(), l.end());
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += l.at(i * 2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
ans = [0] * n

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        ans[a[j] - 1] += 1

re_ans = ans.count(0)
print(re_ans)


Measured memory_bytes: 9172
#include<stdio.h>
#define INF 1000000000
int cost[101][101];
int d[101];
int flag[101];
int n;
void dijkstra(int s){
    int i,j;
    d[s] = 0;
    
    
    while(1){
        int v = -1;
        for(i=0;i<n;i++){
            if(flag[i]==0 && (v==-1 || d[i] < d[v])){
                v = i;
            }
        }
        if(v == -1) break;
        flag[v] = 1;
        for(i=0;i<n;i++){
            int tmp = d[v]+cost[v][i];
            d[i] = d[i] < tmp ? d[i] : tmp;
        }
    }
}
int main(){
    int i,j;
    int u,k,v,c;
    scanf("%d",&n);
    
    for(i=0;i<n;i++) d[i] = INF;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++) cost[i][j] = INF;
    
    for(i=0;i<n;i++){
        scanf("%d%d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d%d",&v,&c);
            cost[u][v] = c;
        }
    }
    dijkstra(0);
    
    for(i=0;i<n;i++){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}



Measured memory_bytes: 2052
#include<stdio.h>
#include<string.h>
int main(void){
int A,B,C,D,E,N,M,x,y,cou=0,cou2,v[1000000],w[1000000],min_i,en=0;
    char S[20],W[100],s[10],X,Y;
   scanf("%d",&A);
   for(int i=1;i<=A;i++){
       cou+=i;
   }
   printf("%d",cou);
   return 0;
}

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

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

    vector<int> w(n);

    for ( int i = 0; i < n; i++ ) {
        cin >> w[i];
    }

    int sum1 = 0;
    int sum2 = 0;
    int diff = 100000;
    int i = n - 1;
    while ( 1 ) {
        if ( i < 0 ) {
            break;
        }
        sum2 = 0;
        sum1 += w[i];
        for ( int j = 0; j < i; j++ ) {
            sum2 += w[j];
        }
//        cout << sum1 << " " << sum2 << endl;
        if ( diff < std::abs(sum2 - sum1) ) {
            break;
        }
        else {
            diff = std::abs(sum2 - sum1);
        }
        i--;
    }

    cout << diff << endl;

    return 0;
}

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

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

  ll ans = 0;

  if (n < 2 && m < 2) {  // 1マス
    ans = 1;
    cout << ans << endl;
    return 0;
  }

  if (n < 2 || m < 2) {  // 横長
    // 端は表
    // 端以外は裏
    ans = max(n - 2, m - 2);
    cout << ans << endl;
    return 0;
  }

  // 外周の角は4回反転するので表
  // 外周の角以外は6回反転するので表
  // 外周以外は9回反転するので裏
  ans += (n - 2) * (m - 2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 2001001;

vector<int> a(MAX_N),b(MAX_N),c(MAX_N);
int n;

void CoutingSort(vector<int> a,vector<int> b,int k){
    rep(i,k+1) c[i] = 0;
    for(int i=1;i<=n;i++) c[ a[i] ]++;
    for(int i=1;i<=k;i++) c[i] = c[i] + c[i-1];
    for(int i=n;i>=1;i--){
        b[c[a[i]]] = a[i];
        c[a[i]]--;
    }
    rep(i,n) if(i!=0) cout << b[i] << " ";
    cout << b[n]<< endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    int mx = 0;
    rep(i,n) cin >> a[i+1],mx = max(mx,a[i]);
    CoutingSort(a,b,mx);

    return 0;
}



Measured memory_bytes: 41956
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main(){

  int a, b;
  cin >> a >> b;

  cout << (a * 3 + b) / 2 << endl; 

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct edge{
  int to,cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){}
};
int n,m;
vector<edge> v[105];
bool used[105];
void dfs(int k){
  if(used[k]) return;
  used[k]=true;
  for(int i=0;i<v[k].size();i++) dfs(v[k][i].to);
}
int main(){
  while(cin>>n>>m,n||m){
    int i,j,k;
    for(i=0;i<105;i++) v[i].clear();
    int a,b,c;
    for(i=0;i<m;i++){
      cin >> a >> b >> c; 
      v[a].push_back(edge(b,c));
      v[b].push_back(edge(a,c));
    }

    fill(used,used+105,false);
    dfs(1);
    bool f=false;
    for(i=1;i<=n;i++) if(!used[i]) f = true;
    if(f){
      cout << -1 << endl;
      continue;
    }

    int l=0,r=10000;
    int mid=(l+r)/2;
    
    while(l<r){
      mid=(l+r)/2;
      //cout << l << ":" <<  mid << ":" << r << endl;
      bool ok=false;
      for(k=0;k<=n+1;k++){
	for(i=0;i<v[k].size();i++){
	  fill(used,used+105,false);
	  //if(v[k][i].to>n) continue;
	  int base=v[k][i].cost;
	  used[k]=true;
	  queue<int> q;
	  q.push(v[k][i].to);
	  while(!q.empty()){
	    int p = q.front();q.pop();
	    if(used[p]) continue;
	    used[p]=true;
	    for(j=0;j<v[p].size();j++){
	      if(v[p][j].cost<=base && base-v[p][j].cost<=mid) 
		q.push(v[p][j].to);
	    }
	  }
	  ok=true;
	  for(j=1;j<=n;j++) if(!used[j]) ok=false;
	  if(ok) break;

	  fill(used,used+105,false);
	  q.push(v[k][i].to);
	  while(!q.empty()){
	    int p = q.front();q.pop();
	    if(used[p]) continue;
	    used[p]=true;
	    for(j=0;j<v[p].size();j++){
	      if(v[p][j].cost>=base && v[p][j].cost-base<=mid) 
		q.push(v[p][j].to);
	    }
	  }
	  ok=true;
	  for(j=1;j<=n;j++) if(!used[j]) ok=false;
	}
	if(ok) break;
      }
      if(ok) r=mid;
      else {
	l=mid;
	if(l+1==r) break;
      }
    }
    
    cout << r << endl;
  }
  return 0;
}

Measured memory_bytes: 1360
#include <iostream>
#include <string>
#include <queue>
#include <numeric>
#include <algorithm>
#include <set>
using namespace std;

string reverse(string str){
	// string rev = "";
	// for(int i=str.size()-1; i>=0; i--){
	// 	rev += str[i];
	// }
	reverse(str.begin(), str.end());
	return str;
}

int main(){

	int m; cin >> m;
	for(int i=0; i<m; i++){
		set<string> train;
		string s; cin >> s;
		int l = s.size();
		for(int j=1; j<l; j++){
			string first = s.substr(0, j);
			string second = s.substr(j);
			train.insert(first + second);
			train.insert(first + reverse(second));
			train.insert(reverse(first) + second);
			train.insert(reverse(first) + reverse(second));
			train.insert(second + first);
			train.insert(second + reverse(first));
			train.insert(reverse(second) + first);
			train.insert(reverse(second) + reverse(first));
		}
		cout << train.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3256
/**********************************
	author:  mariogzsl
**********************************/

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,b,a) for(int i=b-1;i>=a;i--)
#define f first
#define s second
#define puts(x) cout<<x<<endl
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	int m=-1;
	int c, ans=0;
	cin>>N;
	FOR(i,0,N){
		cin>>c;
		if(c>=m)ans++;
		m=max(m, c);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import combinations, permutations


def f(x, lst, rem):
    c = int(1e9+7)
    tpl = ()
    for v in range(len(lst) - rem + 1):
        for t in combinations(lst, v + 1):
            if abs(x - sum(t)) + 10 * v < c:
                c = abs(x - sum(t)) + 10 * v
                tpl = t
    for v in tpl:
        lst.remove(v)
    return c, lst


def main():
    N, A, B, C = map(int, input().split())
    L = [int(input()) for i in range(N)]

    ans = int(1e9+7)
    for ABC in permutations((A, B, C), 3):
        lst = L[:]
        accum = 0
        for i, v in enumerate(ABC):
            c, lst = f(v, lst, 3 - i)
            accum += c
        ans = min(ans, accum)
    print(ans)


main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k, ans = 0;
    cin >>k;
    for(int i = 1; i <= k; i++){
        for( int j = i; j <= k; j++){
            if(i % 2 == 1 && j % 2 == 0){
                ans++;
            }else if(i % 2 == 0 && j % 2 == 1){
                ans++;
            }
        }
    }

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

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod;    }
ll add(ll a, ll b)  { return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;
const int SZ = 2;
const int MOD = 1e9 + 7;

ll fact[nax],invfact[nax],inverse[nax];

void pre()
{
	fact[0] = 1 , fact[1] = 1;
	invfact[0] = 1;
	invfact[1] = 1;
	inverse[1] = 1;

	forn(i,2,nax)
	{
		inverse[i] = mult(mod-(mod/i),inverse[mod%i]);
		fact[i] = mult(fact[i-1],i);
		invfact[i] = mult(invfact[i-1],inverse[i]);
	}
}

int main()
{
	speedup_IO;
	pre();
	ll n,k;
	cin>>n>>k;
	
	ll a[n];
	forn(i,0,n)
	{
		cin>>a[i];
	}

	sort(a,a+n);

	vector<ll>cnt;
	forn(i,0,n)
	{
		ll j = i;
		ll x = 0;
		while(j<n && a[j] == a[i])
		{
			x++;
			j++;
		}
		cnt.pb(x);
		i = j-1;	
	}

	ll maxi = 0,mini = 0;
	if(mini)
	{
		cout<<"hi";
	}

	ll upto = 0;
	for(ll j =cnt.size()-1;j>=0;j--)
	{
		ll x = cnt[j];
		upto += x;
		forn(i,1,min(k,x)+1)
		{
			if(n-upto>=0 && x-i>=0 && n-upto-(k-i)>=0)
			{
				//cout<<fact[n-x]<<endl;
				//cout<<x<<" "<<i<<endl;
				ll y = mult(fact[x],invfact[i]);
				// cout<<fact[x]<<" "<<invfact[i]<<endl;
				// cout<<y<<endl;
				 y = mult(y,invfact[x-i]);
				//cout<<invfact[x-i]<<endl;
				//cout<<y<<endl;
				y = mult(y,fact[n-upto]);
				//cout<<y<<endl;
				y = mult(y,invfact[k-i]);
				y = mult(y,invfact[n-upto-(k-i)]);
				if(a[n-upto]<0)
				{
					a[n-upto]+=mod;
				}

				y = mult(y,a[n-upto]);
				maxi = add(maxi,y);
			}
		}
	}

	upto = 0;
	for(ll j =0;j<(ll)cnt.size();j++)
	{
		ll x = cnt[j];
		upto+=x;
		forn(i,1,min(k,x)+1)
		{
			if(n-upto>=0 && x-i>=0 && n-upto-(k-i)>=0)
			{
				//cout<<fact[n-x]<<endl;
				//cout<<x<<" "<<i<<endl;
				ll y = mult(fact[x],invfact[i]);
				// cout<<fact[x]<<" "<<invfact[i]<<endl;
				// cout<<y<<endl;
				 y = mult(y,invfact[x-i]);
				//cout<<invfact[x-i]<<endl;
				//cout<<y<<endl;
				y = mult(y,fact[n-upto]);
				//cout<<y<<endl;
				y = mult(y,invfact[k-i]);
				y = mult(y,invfact[n-upto-(k-i)]);
				if(a[upto-1]<0)
				{
					a[upto-1]+=mod;
				}
				y = mult(y,a[upto-1]);
				mini = add(mini,y);
			}
		}
	}	
		
	ll ans = sub(maxi,mini);
	//cout<<maxi<<" "<<mini<<endl;
	cout<<ans;
	return 0;
}

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

typedef long long ll;
#define rep(i,a,b,c) for(ll i=(a);i<(b);i+=(c))

int main(void){
    ll A,B,C,K;
    scanf("%lld %lld %lld",&A,&B,&C);
    scanf("%lld",&K);
    while(A>=B&&K>0){
        B=B*2;
        K--;
    }
    while(B>=C&&K>0){
        C=C*2;
        K--;
    }
    if(A<B&&B<C)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 1620
program test
implicit none

integer :: sosuu(55555)=1,i,j,k,nn,n,ans(55555),count=0

read(*,*) n

sosuu(1) = 0

nn = int(55555**0.5)

do i=2,nn
	do j=2,55555
		if(j>i .and. mod(j,i) == 0)then
			sosuu(j) = 0
		endif
	enddo
enddo

count=0
do i=1,55555
	if(sosuu(i)==1 .and. mod(i,10)==1 )then
		count =count + 1
		ans(count)=i
	endif

	if(count == 55)then
	goto 100
	endif

enddo

100 continue

write(*,*) ans(1:n)

end program

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
using namespace std;
int v[100005];
int main() {
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&v[i]);
        ans+=abs(v[i]-v[i-1]);
    }
    ans+=abs(v[n]);
    for(int i=1;i<=n;i++){
        cout<<ans-abs(v[i]-v[i-1])-abs(v[i+1]-v[i])+abs(v[i-1]-v[i+1])<<endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#define fr first
#define sc second
#define MP make_pair
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
using namespace std;

lli gcd(lli a, lli b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
lli cg(lli n) {
	return n ^ (n >> 1);
}
lli SUM(lli a)
{
	return (a * (a + 1) / 2);
}
bool CAN(int x, int y, int n, int m)
{
	if (x >= 0 && y >= 0 && x < n && y < m)
	{
		return true;
	}
	return false;
}
double her(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string strsum(string a, string b)
{
	int p = 0;
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (b.length() < a.length())
	{
		for (int i = b.length(); i < a.length(); i++)
		{
			b += "0";
		}
	}
	else
	{
		for (int i = a.length(); i < b.length(); i++)
		{
			a += "0";
		}
	}

	a += "0", b += "0";
	for (int i = 0; i < a.length(); i++)
	{
		c += (a[i] - '0' + b[i] - '0' + p) % 10 + '0';
		p = (a[i] + b[i] - '0' - '0' + p) / 10;
	}
	if (c[c.length() - 1] == '0') c.erase(c.length() - 1, 1);
	reverse(c.begin(), c.end());
	return c;
}
string strmin(string a, string b)
{
	if (a.length() > b.length()) return b;
	if (b.length() > a.length()) return a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] > b[i]) return b;
		if (b[i] > a[i]) return a;
	}
	return a;
}

char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };



const int N = 1e6 + 30;
const lli mod = 1000000007;

int n;
double a[N];
double pat;
int main()
{
	fastio;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		pat += 1 / a[i];
	}
	pat = 1 / pat;
	cout << pat;
	return 0;
}

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

using namespace std;

const int MAX_N = 100000;
int n,k;
int a[MAX_N], b[MAX_N];

int clr_l(uint v, uint z)
{
  return v & ~((1 << z) - 1);
}

bool flg(uint v, uint z)
{
  return (v & (1 << (z-1))) != 0;
}

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

  uint64_t max_v = 0;
  uint64_t v;
  for (uint z = 1; z <= 31; z++) {
    if (!flg(k, z)) continue;
    v = 0;
    int uk = clr_l(k, z-1);
    for (int i = 0; i < n; i++) {
      if (flg(a[i], z)) continue;
      int ua = clr_l(a[i], z-1);
      if ((uk | ua) == uk) {
        v += b[i];
      }
    }
    max_v = max(max_v, v);
  }
  v = 0;
  for (int i = 0; i < n; i++)
    if ((k | a[i]) == k) v += b[i];

  max_v = max(v, max_v);

  cout << max_v << endl;

  return 0;
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))

l=[0]*(max(a)+1)
for i in range(n):
    l[a[i]]+=1
#print(l)
ans=0
for i in range(len(l)-2):
    ans=max(ans,l[i]+l[i+1]+l[i+2])
if len(l)==1:
    print(l[0])
elif len(l)==2:
    print(sum(l))
else:
    ans=max(ans,l[0]+l[1],l[-1]+l[-2])
    print(ans)

Measured memory_bytes: 13964
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m), n)
	{
		int view[100][100];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				scanf("%d", &view[i][j]);
		int part[4][50][50];
		for (int i = 0; i < m; ++i)
			for (int j = 0; j < m; ++j)
				scanf("%d", &part[0][i][j]);

		for (int k = 1; k < 4; ++k)
			for (int i = 0; i < m; ++i)
				for (int j = 0; j < m; ++j)
					part[k][j][m-i-1] = part[k-1][i][j];

		int x, y;
		x = y = -1;
		for (int i = 0; i <= n-m; ++i)
		{
			for (int j = 0; j <= n-m; ++j)
			{
				for (int k = 0; k < 4; ++k)
				{
					bool ok = true;
					for (int ii = 0; ii < m && ok; ++ii)
						for (int jj = 0; jj < m && ok; ++jj)
							if (part[k][ii][jj] != -1 && part[k][ii][jj] != view[i+ii][j+jj])
								ok = false;

					if (ok)
					{
						int mj;
						for (mj = 0; part[k][0][mj] == -1; ++mj)
							;
						x = j + mj + 1;
						y = i + 1;
						goto End;
					}
				}
			}
		}
End:
		if (x != -1)
			printf("%d %d\n", x, y);
		else
			puts("NA");
	}

	return 0;
}

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

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  
  
  a[0]-=32;
  b[0]-=32;
  c[0]-=32;
  
  cout << a[0] << b[0] << c[0];
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
short n,m,an[105][105];
char a[105][105];
bool flag[105][105];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) 
        for(int j=1;j<=m;j++) {
            cin>>a[i][j];
            if(a[i][j]=='#') flag[i][j]=1;
            else flag[i][j]=0;}
    for(int i=1;i<=n;i++) 
        for(int j=1;j<=m;j++) 
        {
            if(flag[i-1][j]==1) an[i][j]++;
            if(flag[i][j-1]==1) an[i][j]++;
            if(flag[i+1][j]==1) an[i][j]++;
            if(flag[i][j+1]==1) an[i][j]++;
            if(flag[i-1][j+1]==1) an[i][j]++;
            if(flag[i+1][j-1]==1) an[i][j]++;
            if(flag[i+1][j+1]==1) an[i][j]++;
            if(flag[i-1][j-1]==1) an[i][j]++;
        }
    for(int i=1;i<=n;i++) 
    {
        for(int j=1;j<=m;j++) 
        {
            if(a[i][j]=='#') cout<<'#';
            else cout<<an[i][j];
        }
        cout<<endl;
    }
}

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

//const int NIL = -1;

struct Node{
    Node *parent, *left, *right;
    int key;
};
int n, m;
char cmd[20];
Node *root, *NIL;
void preParse(Node *u)
{
    if(u==NIL) return;
    printf(" %d", u->key);
    preParse(u->left);
    preParse(u->right);
}
void inParse(Node *u)
{
    if(u==NIL) return;
    inParse(u->left);
    printf(" %d", u->key);
    inParse(u->right);
}
void Insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;//插入的结点
    z->left = NIL;
    z->right = NIL;

    while(x!=NIL)
    {
        y = x;
        if(z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    z->parent = y;
    if(y==NIL)
    {
        root = z;
    }
    else
    {
        if(z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
    }
}
int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> cmd;
        if(cmd[0]=='i')
        {
            cin >> m;
            Insert(m);
        }
        else
        {
            inParse(root);
            cout << endl;
            preParse(root);
            cout << endl;
        }
    }
    return 0;
}



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

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  string s;
  cin >> s;
  ll res = s.size(), tmp = 0;
  rep(i, s.size()) {
    if (s.at(i) == 'S') tmp++;
    if (s.at(i) == 'T') {
      if (tmp > 0) {
        res -= 2;
        tmp--;
      }
    }
  }
  cout << res << endl;
}

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

#define pb push_back
#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

typedef vector<unsigned char> vb;

const int N = 105;
const int Mod = 998244353;

map<vb, int> dp;

int work(vb o){
	if(!o.size()) return 1;

	int &ans = dp[o];
	if(ans) return ans;

	int n = int(o.size()) - 1;
	int coe = o[n] + 1;
	o.pop_back();
	ans = coe * work(o) % Mod;
	o.pb(coe - 1);

	For(x, 1, (n + 1) / 2){
		int l = n - x + 1, r = n;
		vb v, s = o;
		For(i, l, r) v.pb(o[i]), s.pop_back();

		l -= x, r -= x;
		for(; l >= 0; l -= x, r -= x){
			For(i, l, r) v[i - l] &= o[i], s.pop_back();
			ans = (ans + 1ll * work(v) * work(s)) % Mod;
		}
	}
	
	return ans;
}

char S[N];

int main(){

	scanf("%s", S);
	int n = strlen(S) - 1;
	vb o;
	For(i, 0, n) o.pb(S[i] - '0');
	printf("%d\n", work(o));

	return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    int counter = 0;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
        if(a[i]%2 == 0) counter++;
    }
    int ans = 0;
    while(counter == n){
        counter = 0;
        for (size_t i = 0; i < n; i++){
            a[i] = a[i]/2;
            if(a[i]%2 == 0) counter++;
            }
        ans ++;
    }

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

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

int main(){
    int n;
    int ac,wa,tle,re;
    ac=0;
    wa=0;
    tle=0;
    re=0;
    cin>>n;
    string a;
    rep(i,n){
        cin>>a;
        if (a=="AC") ac++;
        else if(a=="WA")wa++;
        else if (a=="TLE")tle++;
        else if (a=="RE")re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3628
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

a = [[-1] * W for _ in range(H)]

sbs = []
n = 1
for i in range(H):
  si = s[i]
  for j in range(W):
    if si[j] == '#':
      a[i][j] = n
      n += 1
      sbs.append((i, j))

for sb in sbs:
  i, j = sb
  n = a[i][j]
  t, l = i - 1, j - 1
  r = j + 1
  while t > -1:
    if a[t][j] != -1:
      break
    t -= 1
  t += 1
  while l > -1:
    if a[i][l] != -1:
      break
    l -= 1
  l += 1
  while r < W:
    if a[i][r] != -1:
      break
    r += 1
  r -= 1
  for y in range(t, i + 1):
    ay = a[y]
    for x in range(l, r + 1):
      ay[x] = n

for h in range(H - 1, -1, -1):
  if a[h][0] != -1:
    break
h += 1

if h != H:
  for i in range(h, H):
    ai1 = a[i - 1]
    ai = a[i]
    for j in range(W):
      ai[j] = ai1[j]

for i in range(H):
  ai = a[i]
  for w in range(W - 1, -1, -1):
    if ai[w] != -1:
      break
  w += 1

  if w != W:
    n = ai[w - 1]
    for j in range(w, W):
      ai[j] = n

for i in range(H):
  print(*a[i])


Measured memory_bytes: 14352
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll>v;
int main()
{
    ll q,qu,x;
    cin>>q;
    while(q--)
    {
        cin>>qu;
        if(qu==0)
        {
            cin>>x;
            v.push_back(x);
        }
        else if(qu==2)
        {
            v.pop_back();
        }
        else
        {
            cin>>x;
            cout<<v[x]<<endl;
        }
    }
}



Measured memory_bytes: 4968
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

#define REPEAT(flags, k) for (int k = 0; (1 << k) <= flags; k++) if (flags & (1 << k))

int calc(int n, const std::vector<int>& array) {
    int size = 1 << n;
    std::vector<int> table(size);
    table[0] = 0;
    for (int status = 1; status < size; status++) {
        int min = INT_MAX;
        REPEAT(status, i) {
            int previous = status & ~(1 << i);
            int cost = array[i * (n + 1)];
            REPEAT(previous, j) {
                cost = std::min(cost, array[i * (n + 1) + j + 1]);
            }
            min = std::min(min, table[previous] + cost);
        }
        table[status] = min;
    }
    return table[size - 1];
}

int main() {
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        std::vector<int> array(n * (n + 1));
        for (int i = 0; i < n * (n + 1); i++) {
            std::cin >> array[i];
        }
        std::cout << calc(n, array) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3340
#include <iostream>

using namespace std;

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int Mc = E;
    int Mp = 100 + E;

    int maxcc = 0, maxcp = 1;
    int aw, sw;

    for (int w = 0; 100 * A * w <= F; ++w) {
        int w0 = 100 * A * w;
        for (int x = 0; w0 + 100 * B * x <= F; ++x) {
            int w1 = 100 * B * x;
            for (int y = 0; w0 + w1 + C * y <= F; ++y) {
                int s0 = C * y;
                for (int z = 0; w0 + w1 + s0 + D * z <= F; ++z) {
                    int s1 = D * z;
                    if ((w0 + w1) == 0) continue;

                    int cc = s0 + s1;
                    int cp = w0 + w1 + s0 + s1;

                    if (cp * maxcc <= cc * maxcp && cc * Mp <= cp * Mc) {
                        maxcc = cc;
                        maxcp = cp;
                        aw = w0 + w1 + s0 + s1;
                        sw = s0 + s1;
                    }
                }
            }
        }
    }

    cout << aw << " " << sw << endl;

    return 0;
}


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


public class Test
{	
    public static void Main()
	{
	    int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	    
	    if(nums[0] < 1200) Console.WriteLine("ABC");
	    else Console.WriteLine("ARC");
	}
}

Measured memory_bytes: 11348
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


a = input()
n = len(a)
from collections import defaultdict
d = defaultdict(int)
s = 0
ans = 0
for i,c in enumerate(a):
    ans += (s - d[c])
    d[c] += 1
    s += 1
print(ans+1)

Measured memory_bytes: 68364
#include <stdio.h>
 
using namespace std;
 
int main(){
    int r,c,sum,total_sum = 0;
    scanf("%d %d",&r,&c);
    int table[r+1][c+1];
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c+1; j++){
            table[i][j] = 0;
        }
    }
 
    for(int i = 0; i < r; i++){
        sum = 0;
        for(int j = 0; j < c; j++){
            scanf("%d",&table[i][j]);
            sum += table[i][j];
            table[r][j] += table[i][j];
        }
        table[i][c] = sum;
        total_sum += sum;
    }
    table[r][c] = total_sum;
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            printf("%d ",table[i][j]);
        }
        printf("%d\n",table[i][c]);
    }
}


Measured memory_bytes: 2776
#include <stdio.h>

int main() {
int a,b;
scanf("%d %d",&a,&b);//a,b should be 1,2 or 3 and each are different
if((a==1&&b==2)||(a==2&&b==1))
{printf("3\n");}
else if((a==3&&b==2)||(a==2&&b==3))
{printf("1\n");}
else{printf("2\n");}
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0;i<n;i++){
      cin >> d[i];
    }
    //
    sort(d.begin(), d.end());
    //
    cout << d[n/2]-d[n/2-1] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define pb push_back
using namespace std;

vector<vector<int> >a;

int solve(int i){
  
  if(a[i].size()==0) return 0;
  int j,tmp=0,count=0;
  vector<int> t;
  map<int,int> mp;
  for(j=0;j<a[i].size();j++){
    t.pb(solve(a[i][j]));
  }
  //tmp=*max_element(t.begin(),t.end());
  sort(t.begin(),t.end(),greater<int>());
  for(j=0;j<t.size();j++){
    tmp=max(tmp,t[j]+j);
  }
  //if(count>1) tmp+=count-1;
  
  //cout<<tmp<<endl;
  return tmp+1;
}
int main(void){
  int n,i,j,res;
  res=0;

  cin>>n;
  for(i=0;i<=n;i++){
    vector<int> b;
    a.pb(b);
  }

  for(i=2;i<=n;i++){
    cin>>j;
    a[j].pb(i);
  }

  res=solve(1);

  /*
  printf("\n");
  for(i=0;i<=n;i++){
    printf("%d:",i);
    for(j=0;j<a[i].size();j++){
      printf("%d",a[i][j]);
    }
    printf("\n");
  }
  */
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 18160
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

int main(){
  string S;
  cin >> S;
  if(S == "ARC") cout << "ABC" << endl;
  else cout << "ARC" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int a,b;
    cin >> a >> b;
    print((a-1)*(b-1));
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

char data[27];

void inr(char);
void inl(char);

main(){
  char x, a, b;
  int i, n, j;

  scanf("%d", &n);
  getchar();

  for(i=0;i<n;i++){
    for(j=0;j<27;j++){
      data[j]='\0';
    }
    scanf("%c", &x);
    inr(x);
    while(1){
      scanf("%c", &a);
      if(a=='\n') break;
      scanf("%c%c", &b, &x);
      if(b=='>') inr(x);
      else if(a=='<') inl(x);
    }
    printf("%s\n", data);
  }
  return 0;
}


void inr(char x){
  int f=0, i, temp;

  for(i=0;i<27;i++){
    if(data[i]=='\0'){
      temp=i;
      break;
    }
    if(data[i]==x) f=1;
  }
  if(f==0) data[temp]=x;
}

void inl(char x){
  int f=0, i, a[27], temp;

  for(i=0;i<27;i++){
    if(data[i]=='\0'){
      temp=i;
      break;
    }
    if(data[i]==x) f=1;
  }
  if(f==1) return;

  for(i=0;i<=temp;i++){
    a[i]=data[i];
  }
  data[0]=x;

  for(i=0;i<temp;i++){
    data[i+1]=a[i];
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL int
using namespace std;

int n;
LL a[100010];

int main() {
	cin >> n;
	int i, j;
	LL ans = 0;
	LL dis = 0x3f3f3f3f;
	for(i = 0;i ++ < n;) cin >> a[i];
	sort(a+1, a+n+1);
	for(i = 1;i <= n-1;i ++){
        if(a[n] % 2 == 0){
            if(abs(a[i] - a[n]/2) < dis) {
				ans = a[i];
				dis = abs(a[i] - a[n]/2);
			}
        } else {
            if(abs(a[i] - a[n]/2) < dis) {
				ans = a[i];
				dis = abs(a[i]-a[n]/2);
			}
            if(abs(a[i] - a[n]/2 - 1) < dis) {
				ans = a[i];
				dis = abs(a[i] - a[n]/2 - 1);
			}
        }
    }
	cout << a[n] << ' ' << ans;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 500000

struct node
{
    int key;
    struct node* p;
    struct node *l, *r;
} typedef node;

void Insert(int);
int Find(int);
void Print(node*);
void Inorder(node*);
void Preorder(node*);

node *root = NULL;

int main()
{
    int i;
    int n, key;
    int flag;
    char order[7];

    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%s", order);
 
        if(strcmp(order, "insert") == 0)
        {
            scanf("%d", &key);
	        Insert(key);
	    }
	    if(strcmp(order, "find") == 0)
	    {
	        scanf("%d", &key);
	        flag = Find(key);
	        if(flag)
	        printf("yes\n");
	        else
	        printf("no\n");
	    }
        if(strcmp(order, "print") == 0)
        {
            Print(root);
        }
    }
    return 0;
}

void Insert(int key)
{
    node *x, *y, *z;

    x = root;
    y = NULL;
    z = (node*)malloc(sizeof(node));
    z->key = key;
	z->l = NULL;
	z->r = NULL;

    while(x != NULL)
    {
        y = x;
        if(z->key < x->key) x = x->l;
        else x = x->r;
    }
    z->p = y;

    if(y == NULL) 
    root = z;
    else if(z->key < y->key)
    y->l = z;
    else 
    y->r = z;
}

int Find(key)
{
    node *x;
    
    x = root;
    
    while(x != NULL)
    {
        if(key == x->key)
        return 1;
        
        if(key < x->key)
        x = x->l;
        else
        x = x->r;
    }
    return 0;
}
    
void Print(node *x)
{
    Inorder(x);
    printf("\n");
    Preorder(x);
    printf("\n");
}
 
void Inorder(node *x)
{
    if(x == NULL) return;

    Inorder(x->l);
    
    printf(" %d", x->key);
    
    Inorder(x->r);
}

void Preorder(node *x)
{
    if(x == NULL) return;
    
    printf(" %d", x->key);

    Preorder(x->l);
    Preorder(x->r);
}

Measured memory_bytes: 19360
import sys
import collections

def main(S, T):
    print(S, file=sys.stderr)
    print(T, file=sys.stderr)

    m = dict()
    for s, t in zip(S, T):
        if s in m and m[s] != t:
            return "No"
        m[s] = t
    print("  ".join(m), file=sys.stderr)
    print("  ".join(m.values()), file=sys.stderr)
    c = set()
    for t in m.values():
        if t in c:
            return "No"
        c.add(t)
    return "Yes" 

assert main("chokudai", "redcoder") == "No"
assert main("azzel", "apple") == "Yes"
assert main("abcdefghijklmnopqrstuvwxyz", "ibyhqfrekavclxjstdwgpzmonu") == "Yes"
S = input()
T = input()
print(main(S, T))


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

int main(){
  int n, m;
  cin >> n >> m;
  
  vector<int> a(m);
  int sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  if (sum <= n) cout << n - sum << endl;
  else cout << "-1" << endl;
}

Measured memory_bytes: 3640
n=int(input())
s=[[0] for _ in range(n)]
for i in range(n):
    s[i]=input()

ans=0
for p in range(n):
    cnt=0
    t=[[0] for _ in range(n)]
    for i in range(n):
        t[i]=s[(i+p)%n]
    for r in range(n):
        for l in range(n):
            if t[r][l]==t[l][r]:
                cnt+=1
    if cnt==n**2:
        ans+=1
print(ans*n)


Measured memory_bytes: 43440
n,k = gets.split.map(&:to_i)
cnt = [0]*n
k.times do
  d = gets.to_i
  a = gets.split.map(&:to_i)
  a.each do |v|
    cnt[v-1] += 1
  end
end
p cnt.select{|v|v==0}.size 


Measured memory_bytes: 14340
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int
#define Vec vector

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int N,A,B,C;
	cin >> N >> A >> B >> C;
	Vec<int> L(N);
	for(int i=0;i<N;i++) cin >> L[i];
	
	int mi = (int) 1e9;
	
	for(int i=1;i<(1 << N); i++){
		for(int j=1;j<(1 << N); j++){
			for(int k=1;k<(1 << N); k++){
				if(((i & j) > 0) || ((j & k) > 0) || ((k & i) > 0)) continue;
				int a = 0;
				int b = 0;
				int c = 0;
				int tot = 0;
				int ca = 0, cb = 0, cc = 0; 
				for(int t=0;t<N;t++){
					if((i >> t) % 2 == 1){
						a += L[t];
						ca++;
					}
					if((j >> t) % 2 == 1){
						b += L[t];
						cb++;
					}
					if((k >> t) % 2 == 1){
						c += L[t];
						cc++;
					}
				}
				tot += max(0,(ca - 1)) * 10;
				tot += max(0,(cb - 1)) * 10;
				tot += max(0,(cc - 1)) * 10;
				tot += abs(a - A);
				tot += abs(b - B);
				tot += abs(c - C);
//cout << i << " " << j << " " << k <<" : " << a << " " << b << " " << c << " tot:" << tot << endl;
				mi = min(mi, tot);
			}
		}
	
	}
	
	cout << mi << endl;
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// 繰り返し二乗法 //////////

ll power(ll a,ll b){
  ll res=1;
  while(b>0){
    if(b&1) res=res*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return res;
}

//////////////////////////////////////////////////

int main(){
  ll N,ans=0;
  cin>>N;
  bool CAN=true; //全て偶数かどうか
  int A[N];
  char B[N];
  REP(i,N){
    cin>>B[i];
    A[i]=B[i]-'0'-1;
    if(A[i]%2!=0) CAN=false;
  }
  
  if(CAN){
    REP(i,N) A[i]/=2;
  }
  else{
    REP(i,N){
      if(A[i]==2) A[i]=0;
    }
  }
  
  ///////
  
  vector<ll> L;
  REP(i,N){
    L.PB(A[i]);
  }
  
  while(L.size()>1){
    vector<ll> LL;
    ll T=-1,S=L.size(),P=0LL;
    while(S>0){
      S/=2;
      T++;
    }
    REP(i,power(2,T)) P^=L[i];
    LL.PB(P);
    
    for(ll i=power(2,T); i<L.size(); ++i){
      P^=L[i];
      P^=L[i-power(2,T)];
      LL.PB(P);
    }
    L=LL;
  }
  
  ans=L[0];
  
  ///////
  
  if(CAN) ans*=2;
  co(ans);
  return 0;
}

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


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll n;
	string s;
	vector<string> v;
	map<string ,ll> mp;
	ll m1=0;
	map<string ,ll> :: iterator it;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>s;
		mp[s]++;
		m1=max(mp[s],m1);
	}
	for(it=mp.begin();it!=mp.end();it++)
	{
		if(it->second==m1)
		{
			//cout<<(it->first);
			v.push_back(it->first);
		}
	}
	sort(v.begin(),v.end());
	for(ll i=0;i<v.size();i++)
	{
		cout<<v[i]<<endl;
	}
	
return 0;
}


Measured memory_bytes: 25584
N = int(input())
h = [int(_) for _ in input().split()]

dp = [0] * N
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    cost1 = dp[i - 1] + abs(h[i] - h[i - 1])
    cost2 = dp[i - 2] + abs(h[i] - h[i - 2])
    dp[i] = min(cost1, cost2)

print(dp[N - 1])

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

#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define per(i,n) for (int i=(int)(n)-1;i>=0;i--)
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pii pair<int,int>
#define vi vector <int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=1e5+3;

int n,m,w[MAXN],ans;
vi v,nv,g[MAXN];

void go(){
	for (int &i:v){
		for (int &j:g[i]){
			w[j]--;
			if (w[j]==0) nv.pb(j);
		}
	}
}

int main(){
	fio;
	int x,y;
	cin>>n>>m;
	rep(i,m){
		cin>>x>>y;
		g[x].pb(y);
		w[y]++;
	}
	For(i,n){
		if (w[i]==0){
			v.pb(i);
		}
	}
	while (v.size()){
		go();
		ans++;
		swap(v,nv);
		nv.clear();
	}
	cout<<ans-1<<endl;
	re 0;
}

Measured memory_bytes: 6144
#include <iostream>

using namespace std;

int main()
{
  int l[110];
  int n;
  int i;
  int sum = 0;
  int max = -1;
  
  cin >> n;
  for(i=0; i<n; i++)
  {
    cin >> l[i];
    sum += l[i];
    max = (max < l[i]) ? l[i] : max;
  }
  sum -= max;
  if(sum > max)
    cout << "Yes\n";
  else
    cout << "No\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll int a,b,ans,p;
cin>>a>>b;
if(a==b)
{
    ans=a;
}
else
{
    p=__gcd(a,b);
    ans=(a*b)/p;
}

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


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

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

const int N = 5e5 + 7;


struct RMQ {
        vector <int> t;
        int n;
        RMQ(int n) : n(n) {
                t.resize(n << 1, 0);
        }
       
        void modify(int p, int v) {
                for(t[p += n] = v; p > 1; p >>= 1) t[p >> 1] = t[p] + t[p ^ 1];
        }
        int query(int l, int r) { int res = 0;
                for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
                        if(l & 1) res += t[l++];
                        if(r & 1) res += t[--r];
                }
                return res;
        }
};

int lst[N], a[N], ans[N];

vector <pair <int, int> > qq[N];

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	RMQ T(n + 7);
	for(int i = 1; i <= q; i++) {
		int l, r; cin >> l >> r;
		qq[r].push_back(make_pair(l, i));
	}
	
	for(int i = 1; i <= n; i++) {
		if(lst[a[i]]) {
			T.modify(lst[a[i]], 0);
		} 
		T.modify(i, 1);
		lst[a[i]] = i;
		for(auto z: qq[i]) {
			ans[z.second] = T.query(z.first, i);
		}
	}
	for(int i = 1; i <= q; i++) {
		cout << ans[i] << endl;
	}
}

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

int main(void){
	int i;
	int n;
	int sum,len,count;
	char s[1004];

	scanf("%d",&n);
	while(n--){
		scanf("%s",s);

		len = strlen(s);
		sum = 0;
		for(i=0;i<len;i++)
			sum += s[i] - '0';

		count = (len - 1) + (sum - 1) / 9;
		printf("%s wins.\n",count % 2 == 0 ? "Audrey" : "Fabre");
	}

	return 0;
}

Measured memory_bytes: 0
//dont try to understand my code i really dont understand it 
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<vector>
#include <queue>
#include <stack>
#include<algorithm>
#include<memory.h>
using namespace std;
typedef long long ll;
#define f( i , x , n ) for(int i = x; i < (int)(n); ++i)
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef pair<int, int> ii;
const double PI = acos(-1.0);
//const ll oo = 1000000000000030200;
//const ll F = LLONG_MIN;	
//const int A = 1234567;
typedef long long ll;
// write what you need here : ... 
int arr[102002];
int main()
{
	int a;
	cin >> a;
	for (int i = 0; i < a;i++)
	{
		int temp;
		scanf("%d", &temp);
		arr[temp]++;
	}

	int mx = 0; 
	for (int i = 0; i < 100021; i++)
	{
		mx = max(mx, arr[i] + arr[i + 1] + arr[i + 2]);
	}

	cout << mx;

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);
    
    while (in.hasNext()) {
      int N = in.nextInt();
      int M = in.nextInt();
      int[] A = new int[M];

      for (int i = 0; i < N; ++i) {
        int K = in.nextInt();

        for (int j = 0; j < K; ++j) {
          ++A[in.nextInt() - 1];
        }
      }
      
      int count = 0;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] == N) {
          ++count;
        }
      }

      System.out.println(count);
    }
  }
}

Measured memory_bytes: 22352
#include <iostream>
#include <cctype>
#include <string>


int main()
{
	std::string moji;
	std::getline(std::cin, moji);

	for(int i=0; i<moji.size(); i++)
	{
		if(islower(moji[i]))
		{
			moji[i] = toupper(moji[i]);
			std::cout << moji[i];
		}
		else if (isupper(moji[i]))
		{
			moji[i] = tolower(moji[i]);
			std::cout << moji[i];
		}
		else
		{
			std::cout << moji[i];
		}

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

}

Measured memory_bytes: 1176