akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)


map<string, int> mp;
#define ll long long
string s[50];
int h, w;
char compute(int i, int j) {
    int dx[] = { -1, -1,  0,  1,  1,  1,  0, -1 };
    int dy[] = { 0, -1, -1, -1,  0,  1,  1,  1 };
    int res = 0;
    if (s[i][j] == '#') return '#';
    for (int k = 0; k<8; ++k) {
        int x = i + dx[k], y = j + dy[k];
        if (0 <= x && x < h && 0 <= y && y<w && s[x][y] == '#') ++res;
    }
    return '0' + res;
}
int main() {
  
    cin >> h >> w;
   
    rep(i, h) {
        cin >> s[i];
    }
    for (int i = 0; i<h; ++i) {
        for (int j = 0; j<w; ++j) {
            cout << compute(i, j);
        }
        cout << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int N,M;
#define MAXN 100001
int X[MAXN];
int main(){
    cin >> N >> M;
    rep(i,M){
        cin >> X[i];
        X[i]--;
    }
    int ans = 0;
    sort(X,X+M);
    int skip = N-1;
    priority_queue<int> V;
    if(N>=M)cout << ans << endl;
    else{
        rep(i,M-1){
            V.push(X[i+1]-X[i]);
        }
        ans = X[M-1]-X[0];
        rep(i,skip){
            
            ans -= V.top();
            V.pop();
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1276
#include <stdio.h>
#include <math.h>
int main(void){
    int N, K, D[10], fase[6], keta=0, kane=0;
    scanf("%d%d", &N, &K);
    for(int i=0; i<K; i++) scanf("%d", &D[i]);
    kane = N;
    for(;N;N/=10){
        fase[keta] = N%10;
        for(int i=0; i<K; i++){
            if(fase[keta]==D[i]) {
                kane++;
                N = 10*kane;
                keta=-1;
                break;
            }
        }
        keta++;
    }
    printf("%d", kane);
    return 0;
}

Measured memory_bytes: 1704
s = input()

l = s.split("/")

n1 = int(l[0])
n2 = int(l[1])

if n1<2019:
    print("Heisei")
elif n1>2019:
    print("TBD")
elif n2<=4:
    print("Heisei")
elif n2>4:
    print("TBD")


Measured memory_bytes: 2940
from itertools import product

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

abc = [a, b, c]

res = float('inf')
for p in product(range(4), repeat=n):
    num = [0, 0, 0, 0]
    le = [0, 0, 0, 0]
    for i, category in enumerate(p):
        num[category] += l[i]
        le[category] += 1
    tmp = 0
    if le[0] * le[1] * le[2] == 0:
        continue
    for i in range(3):
        tmp += abs(num[i] - abc[i]) + 10 * (le[i] - 1)
    res = min(res, tmp)

print(res)



Measured memory_bytes: 42732
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn prime_factors(n: u64) -> HashMap<u64, u64> {
    let limit = n;
    let mut n = n; 
    let mut prime_numbers: HashMap<u64, u64> = HashMap::new();
    let mut candidate = 2;
    while n > 1 {
        if candidate * candidate > limit {
            prime_numbers.insert(n, 1);
            return prime_numbers;
        }
        while n % candidate == 0 {
            let val = prime_numbers.entry(candidate).or_insert(0);
            *val += 1;
            n /= candidate;
        }
        candidate += 1;
    }
    return prime_numbers;
}

fn binary_power(x: u64, n: u64) -> u64 {
    if n == 0 {
      return 1;
    }
    if n % 2 == 0 {
      return (binary_power(x, n / 2) % MOD).pow(2) % MOD;
    } else {
      return binary_power(x, n - 1) % MOD * x % MOD;
    }
}
  
fn inverse_mod(n: u64) -> u64 {
    binary_power(n, MOD-2)
} 

fn combination(fact: &Vec<u64>, n: u64, m: u64) -> u64 {
    fact[n as usize] * inverse_mod(fact[(n-m) as usize]) %MOD * inverse_mod(fact[m as usize])%MOD
}

fn main() {
    let (n, m) = input_tuple();
    let factor_map = prime_factors(m);
    let mut fact: Vec<u64> = Vec::new();
    fact.push(1);
    for i in 1..n + 30 {
        fact.push(fact[i as usize - 1]*(i) % MOD);
    }
    let mut sum = 1;
    for v in factor_map.values() {
        sum *= combination(&fact, v + n - 1, *v);
        sum %= MOD;
    }
    println!("{}", sum);
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
const int maxn=100010;
int tree[maxn<<2],arr[maxn];
void build(int node, int l, int r) {
  if(l == r) { tree[node] = arr[l]; return; } 
  int mid = l + r >> 1;
  build(node<<1, l, mid);
  build(node<<1|1, mid+1, r);
  tree[node] = __gcd(tree[node<<1] , tree[node<<1|1]); 
}
int query(int node, int l, int r, int i, int j) {
  if(r < i || l > j) return 0;
  if(i <= l && r <= j) {
    return tree[node]; 
  } int mid = l + r >> 1;
  return __gcd(query(node << 1, l, mid, i, j) , 
         query(node << 1|1, mid+1, r, i,j));
}
int main(int argc, char const *argv[])
{
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)scanf("%d",&arr[i]);
  build(1,1,n);
  int mx=max(query(1,1,n,2,n),query(1,1,n,1,n-1));
  for(int i=2;i<n;i++)mx=max(mx,__gcd(query(1,1,n,1,i-1),query(1,1,n,i+1,n)));
  printf("%d\n", mx);
  return 0;
}

Measured memory_bytes: 1664
s = int(input())
list = [[0]*1000000]
list[0] =s
key = 0
for i in range(1,100000):
    if (list[i-1])%2 == 0:
            key = (list[i-1])//2
            if key in list:
                print(i+1)
                exit()
            else:
                list.append(key)

    else:
            key = 3*(list[i-1])+1
            if key in list:
                print(i+1)
                exit()
            else:
                list.append(key) 

Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
double INF=1<<29;
typedef long long ll;
typedef complex<double> P;
typedef pair<int,int> PP;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
  }
}
int p[10],r[10];
void init(){for(int i=0;i<10;i++)p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}
bool same(int x,int y){return find(x)==find(y);}

P PerpendicularBisector(P a,P b) {
  double x,y;
  if(b.imag()-a.imag()) {
    x=-(b.real()-a.real())/(b.imag()-a.imag());
    y=-(a.real()+b.real())/2*x+(a.imag()+b.imag())/2;
  } else {
    x=INF;
    y=(a.real()+b.real())/2;
  }
  if(x==-0) x=0;
  return P(x,y);
}

P a[10];
ll n,k,ans;
map<P,vector<PP> > m;
map<int,P> ma;
void dfs(int l, ll t) {
  bool f=1;
  for(int i=1; i<n; i++) {
    if(!same(0,i)) {
      f=0;
      break;
    }
  }
  if(f) ans=min(ans,t);
  if(t>=n-2) return;
  for(int i=l; i<k; i++) {
    int pp[n],rr[n];
    for(int j=0; j<n; j++) pp[j]=p[j],rr[j]=r[j];
    vector<PP> v=m[ma[i]];
    for(int j=0; j<v.size(); j++) unite(v[j].first,v[j].second);
    dfs(i+1,t+1);
    for(int j=0; j<n; j++) p[j]=pp[j],r[j]=rr[j];
  }
}

int main() {
  cin >> n;
  for(int i=0,x,y; i<n; i++) {
    cin >> x >> y;
    a[i]=P(x,y);
  }
  for(int i=0; i<n; i++) {
    for(int j=i+1; j<n; j++) m[PerpendicularBisector(a[i],a[j])].push_back(PP(i,j));
  }
  k=0;
  for(map<P,vector<PP> >::iterator it=m.begin();it!=m.end();it++) ma[k++]=it->first;
  init();
  ans=n-1;
  dfs(0,0);
  cout << ans << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int x,y,a,b,c;

  cin >> x >> y >> a >> b>>c;
  vector<ll> p(a),q(b),r(c);
  vector<ll> sp(x+1,0), sq(y+1,0), sr(c+1,0);

  REP(i,a)cin >> p[i];
  REP(i,b)cin >> q[i];
  REP(i,c)cin >> r[i];

  sort(ALL(p));
  reverse(ALL(p));
  sort(ALL(q));
  reverse(ALL(q));
  sort(ALL(r));
  reverse(ALL(r));

  REP(i,x){
    sp[i+1] = sp[i]+p[i];
  }
  REP(i,y){
    sq[i+1] = sq[i]+q[i];
  }
  REP(i,c){
    sr[i+1] = sr[i]+r[i];
  }

  vector<ll> nn;
  REP(i,x)nn.push_back(p[i]);
  REP(i,y)nn.push_back(q[i]);
  REP(i,c)nn.push_back(r[i]);

  sort(ALL(nn));
  reverse(ALL(nn));

  ll ans=0;
  REP(i,x+y)ans+=nn[i];

  cout << ans << endl;

}



Measured memory_bytes: 10992
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_N = 100000;



int main(int argc, char *args[]) {
	int N;
	cin >> N;
	int B[110];
	int A[110];
	int ans = 0;
	for (int i = 0; i < N - 1; i++) {
		cin >> B[i];
	}
	A[0] = B[0];
	for (int i = 0; i < N - 1 ; i++) {
		A[i + 1] = min(B[i], B[i + 1]);
	}
	A[N - 1] = B[N - 2]; 
	for (int i = 0; i < N; i++) {
		ans += A[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>

#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  For(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define chk(a) rep(i, a.size()) cout << a[i] << " "
#define SORT(c) sort((c).begin(),(c).end())
#define ll long long
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)


using namespace std;
typedef pair<int, int> pii;
#define WARU 1000000007;

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

int main(void) {
	int n, a, b;
	cin >> n >> a >> b;
	int genzai = 0;
	int gaikoku = 0;
	rep(i, n) {
		char str;
		cin >> str;
		if (str == 'c') {
			cout << "No" << endl;
		}
		else if (str == 'a') {
			if (genzai < (a + b)) {
				cout << "Yes" << endl;
				genzai++;
			}
			else {
				cout << "No" << endl;
			}
		}else if (str=='b'){
			if ((genzai < a + b) && (gaikoku < b)) {
				cout << "Yes" << endl;
				genzai++;
				gaikoku++;
			}
			else {
				cout << "No" << endl;
			}

		}


	}

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int min(int a, int b)
{
	if (a > b){
		return (b);
	}
	return (a);
}

int main(void)
{
	int n, m;
	int tx, ty;
	int ans;
	int i;
	
	scanf("%d", &n);
	scanf("%d", &m);
	
	for (i = 0; i < m; i++){
		scanf("%d%d", &tx, &ty);
		tx = tx >= n / 2 ? n - tx + 1 : tx;
		ty = ty >= n / 2 ? n - ty + 1 : ty;
		
		ans = (min(tx, ty) % 3) ? min(tx, ty) % 3 : 3;
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 0
from operator import itemgetter
import math
N,H = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()]for _ in range(N)]
ab.sort(key = itemgetter(1),reverse = True)
left = H
cnt = 0
max_a = max(ab,key=itemgetter(0))[0]

for i in ab:
    if(i[1]>max_a):
        left -= i[1]
        cnt += 1
    else:
        cnt += math.ceil(left/max_a)
        left = 0
        break
    
    if(left<=0):
        break
        
if(left>0):
    cnt += math.ceil(left/max_a)
print(cnt)


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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


int main() {
   int H, W;
   cin >> H >> W;
   int cnt = 0;
   rep (i, H) {
      rep (j, W) {
         string s;
         cin >> s;
         if (s == "snuke") cout << char('A'+j) << i+1 << endl;
      }
   }

   return 0;
}

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

int main(){
    int n;
	cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    int count = 0;
    for(int i = 0;i < n;i++){
        if(a[i] == 2 || a[i] == 3 || a[i] == 5 || a[i] == 7){
            count++;
            continue;
        }
        else if(a[i] % 2 == 0){
            continue;
        }
        bool judge = true;
        for(int j = 3;j <= sqrt(a[i]);j += 2){
            if(a[i] % j == 0){
                judge = false;
            }
        }
        if(judge){
            count++;
        }
    }
    cout << count << endl;
}




Measured memory_bytes: 3112
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
	int n,a[100]={},alice=0,bob=0,max=0;
	cin >> n;
	for(int i=0;i<n;i++){
		scanf("%d ",&a[i]);
	}
	sort(a,a+n,greater<int>());	
	for(int i=0;i<n;i++){
		if(i%2 == 0)alice+=a[i];
		else bob+=a[i];
	}
	cout << alice-bob << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int r, c;
  int s[101][101] = {{0}};
  cin >> r >> c;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      cin >> s[i][j];
      s[i][c] += s[i][j];
      s[r][j] += s[i][j];
      s[r][c] += s[i][j];
    }
  }
  for (int i = 0; i < r + 1; ++i) {
    const char* sep = "";
    for (int j = 0; j < c + 1; ++j) {
      cout << sep << s[i][j];
      sep = " ";
    }
    cout << endl;
  }
  return 0;
} 



Measured memory_bytes: 3100
from sys import stdin
# import numpy as np
# import math
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

N = int(stdin.readline().rstrip().split()[0])

_A = 0
AB = 0
B_ = 0
B_A = 0
for _ in range(N):
  s = stdin.readline().rstrip().split()[0]
  AB += s.count("AB")
  a=0
  b=0
  if s[0] == "B":
    b = 1
  if s[-1] == "A":
    a = 1
  if a == 1 and b == 1:
    B_A += 1
  _A += a
  B_ += b

if _A == B_ == B_A == 0:
  print(AB)
elif _A == B_ == B_A:
  print(max(0, AB+B_A-1))
else:
  _AB_ = min(_A, B_)
  print(AB+_AB_)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair

using namespace std;

int n, m;
int deg[100010], u[100010], v[100010];
vector<int> G[100010], T[100010];
bool vis[100010], t_edge[100010];

void dfs(int p)
{
	vis[p] = true;
	for (int i = 0; i < G[p].size(); i++)
	{
		int to = (u[G[p][i]] == p ? v[G[p][i]] : u[G[p][i]]);
		if (vis[to]) continue;
		t_edge[G[p][i]] = true;
		dfs(to);
	}
}

void solve(int p, int fa)
{
	for (int i = 0; i < T[p].size(); i++)
	{
		int to = T[p][i];
		if (to == fa) continue;
		solve(to, p);
	}
	assert(p != 1 || deg[p] % 2 == 0);
	if (deg[p] & 1)
	{
		deg[p]--;
		cout << fa << ' ' << p << endl;
	}
	else if (fa)
	{
		cout << p << ' ' << fa << endl;
		deg[fa]--;
	}
}

int main()
{
	ios::sync_with_stdio(false);
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		cin >> u[i] >> v[i];
		G[u[i]].push_back(i);
		G[v[i]].push_back(i);
		deg[u[i]]++, deg[v[i]]++;
	}
	if (m & 1)
	{
		cout << -1 << endl;
		return 0;
	}
	dfs(1);
	for (int i = 1; i <= m; i++)
		if (!t_edge[i])
		{
			cout << u[i] << ' ' << v[i] << endl;
			deg[v[i]]--;
		}
		else
		{
			T[u[i]].push_back(v[i]);
			T[v[i]].push_back(u[i]);
		}
	solve(1, 0);
	return 0;
}


Measured memory_bytes: 21504
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const long long mod=1e9+7;
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; }
typedef pair<int, int> P;
int main(){
int n,d;
cin>>n>>d;
vector<int> a(n);
vector<P> b(n);
ll sum=0;
for(int i=0;i<n;i++){
    a.at(i)=d+i;
    sum+=a.at(i);
    b.at(i)=P(abs(a.at(i)),i);
}
sort(b.begin(),b.end());

cout<<sum-a.at(b.at(0).second)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
    char a[20000];
    scanf("%s",a);
        printf("%c",a[0]);
    scanf("%s",a);
        printf("%c",a[0]);
    scanf("%s",a);
        printf("%c\n",a[0]);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
// #include <algorithm>
#include <math.h>
using namespace std;
using ll = long long;

int countDigits(ll a) {
  int digits = 0;
  while(a > 0) {
    a /= 10;
    digits++;
  }
  return digits;
}

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

  int min = countDigits(n);

  for(ll a = 1ll; a*a <= n; ++a) {
    if(n % a != 0) continue;
    const ll b = n / a;
    const int greaterDigits = max(countDigits(a), countDigits(b));
    if(min > greaterDigits) {
      min = greaterDigits;
    }
  }

  cout << min;
  return 0;
}


Measured memory_bytes: 256
use itertools::Itertools as _;
use proconio::input;
use proconio::marker::Bytes;

fn main() {
    input! {
        n: usize,
        s: Bytes,
    }

    let mut nums = [0; 256];
    for &c in &s {
        nums[usize::from(c)] += 1;
    }

    let mut ans = 0;
    for i in 0..n - 1 {
        let mut nums = [0; 256];
        nums[usize::from(s[i + 1])] += 1;
        for k in i + 2..n {
            if let Ok(&rest) = [b'R', b'G', b'B']
                .iter()
                .filter(|&&c| !(c == s[i] || c == s[k]))
                .exactly_one()
            {
                ans += nums[usize::from(rest)];
                ans -= u64::from((k - i) % 2 == 0 && s[usize::from((i + k) / 2)] == rest);
            }

            nums[usize::from(s[k])] += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2132
# -*- coding: utf-8 -*-
"""
Created on Sat May 30 11:26:40 2020

@author: naoki
"""

N = int(input()) # trainingをする回数
power = 1 # 最初のパワー

for i in range(1,N+1):
    power = (power*i)%(10**9+7) # powerを10^9+7で割った値を出力
print(power)    

    

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  REP(i, h) REP(j, w) cin >> s[i][j];
  int l[h][w], r[h][w], u[h][w], d[h][w];
  REP(i, h) REP(j, w) l[i][j] = r[i][j] = u[i][j] = d[i][j] = 0;
  REP(i, h) REP(j, w) {
    if (s[i][j] == '#')
      l[i][j] = 0;
    else if (j == 0)
      l[i][j] = 1;
    else
      l[i][j] = l[i][j - 1] + 1;
  }
  REP(i, h) RREP(j, w) {
    if (s[i][j] == '#')
      r[i][j] = 0;
    else if (j == w - 1)
      r[i][j] = 1;
    else
      r[i][j] = r[i][j + 1] + 1;
  }
  REP(i, h) REP(j, w) {
    if (s[i][j] == '#')
      u[i][j] = 0;
    else if (i == 0)
      u[i][j] = 1;
    else
      u[i][j] = u[i - 1][j] + 1;
  }
  RREP(i, h) REP(j, w) {
    if (s[i][j] == '#')
      d[i][j] = 0;
    else if (i == h - 1)
      d[i][j] = 1;
    else
      d[i][j] = d[i + 1][j] + 1;
  }
  int ans = 0;
  REP(i, h) REP(j, w) ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 66688
def main():
  N = int(input())

  for x in range(N // 4 + 1):
    for y in range((N - x * 4) // 7 + 1):
      if x * 4 + y * 7 == N:
        print('Yes')
        return
  print('No')


if __name__ == "__main__":
  main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define ws cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

int main(void) {
    int n, q;
    cin >> n >> q;
    string s; cin >> s;
    
    vector<int> as, cs;
    cs.push_back(0);
    
    vector<int> acnt(n+1, 0), ccnt(n+1, 0);
    int cnt = 0;
    repeat_from_to (i, 1, n-1) {
        if (s[i-1] == 'A' and s[i] == 'C') {
            ++cnt;
            as.push_back(i);
            cs.push_back(i+1);
            acnt[i] = cnt;
            ccnt[i+1] = cnt;
        }
    }
    
    rep (q) {
        int l, r;
        cin >> l >> r;
        int x, y;
        auto ait = lower_bound(as.begin(), as.end(), l);
        if (ait == as.end()) {
            cout << 0 << endl;
            continue;
        }
        x = acnt[*ait];
        
        //dump(l); dump(r); dump(x); el;
        
        auto cit = lower_bound(cs.begin(), cs.end(), r);
        if (cit == cs.end() or r != *cit) y = ccnt[*(cit-1)];
        else y = ccnt[*cit];
        
        cout << y - x + 1 << endl;
    }
}

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

ac = 0
wa = 0
tle = 0
re = 0

for _ in range(N):
    judge = input()
    if judge == "AC":
        ac += 1
    if judge == "WA":
        wa += 1
    if judge == "TLE":
        tle += 1
    if judge == "RE":
        re += 1

print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}")


Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int t[n];
	int total = 0;
	for (int i=0; i<n; i++) {
		cin >> t[i];
		total += t[i];
	}
	int m;
	cin >> m;
	for (int i=0; i<m; i++) {
		int x, y;
		cin >> x >> y;
		--x;
		cout << total - t[x] + y << '\n';
	}
	
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    int X[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    int x[N];
    for (int i = 0; i < N; i++)
        x[i] = X[i];
    sort(x, x+N);

    int l, u;
    l = x[N/2-1];
    u = x[N/2];
    for (int i = 0; i < N; i++) {
        if (X[i] <= l) {
            cout << u << endl;
        } else {
            cout << l << endl;
        }
    } 
    

    
}

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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MAXN = 510;
int n;
int p[MAXN * MAXN];

void read() {
	cin >> n;
	for (int i = 0; i < n * n; i++) {
		cin >> p[i];
		p[i]--;
	}
}

int ans;

int dist[MAXN][MAXN];
bool used[MAXN][MAXN];

void build() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			used[i][j] = false;
			dist[i][j] = n;
			chkmin(dist[i][j], i);
			chkmin(dist[i][j], n - i - 1);
			chkmin(dist[i][j], j);
			chkmin(dist[i][j], n - j - 1);
		}
	}
}

vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};

bool checkCell(int x, int y) {
	return x >= 0 && x < n && y >= 0 && y < n;
}

void upd(int x, int y) {
	//cout << "x, y = " << x << " " << y << endl;
	ans += dist[x][y];
	//cout << "dist[x][y] = " << dist[x][y] << endl;
	queue<pair<int, int>> q;
	q.push({x, y});
	used[x][y] = true;
	while (!q.empty()) {
		auto v = q.front();
		x = v.first;
		y = v.second;
		q.pop();
		for (int it = 0; it < 4; it++) {
			int nx = x + dx[it], ny = y + dy[it];
			if (!checkCell(nx, ny)) continue;
			int nd = dist[x][y];
			if (!used[x][y]) nd++;
			//cout << "x, y = " << x << " " << y << " used[x][y] = " << used[x][y] << endl;
			if (dist[nx][ny] <= nd) continue;
			dist[nx][ny] = nd;
			//cout << "nx, ny = " << nx << " " << ny << " nd = " << nd << endl;
			q.push({nx, ny});
		}
	}
}

void wr() {
	cout << "dist = " << endl;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << dist[i][j] << " ";
		}
		cout << endl;
	}
	cout << "used = " << endl;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << used[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
}

void run() {
	build();
	//wr();
	ans = 0;
	for (int i = 0; i < n * n; i++) {
		upd(p[i] / n, p[i] % n);
	//	wr();
	}
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 5904
#include<stdio.h>
#define N 100
int bubblesort(int * ,int);
void swap(int *,int *);

int main(){
  int n,i,j;
  int A[N];//配列の宣言
  scanf("%d",&n);//数列の長さの入力
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);//配列の要素を入力
  }
  
    j=bubblesort(A,n);//並び換えを行う関数の呼出
    //並び換えをした回数を変数jに保存

  //出力
  for(i=0;i<=n-1;i++){
    if(i==n-1)
      printf("%d\n",A[n-1]);//一番最後の出力に余計な空白を出力しない
    else{
      printf("%d ",A[i]);
    }
  }
  printf("%d\n",j);//並び換え回数の出力

  return 0;
}
int bubblesort(int *A,int n){
  int i,j,count=0;
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	swap(&A[j],&A[j-1]);
      count++;
      }
    }
  }
   return count;
}
 

  
void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    n -= 2;
    if (a > b)
        cout << 0 << endl;
    else if (a == b)
        cout << 1 << endl;
    else if (n < 0)
        cout << 0 << endl;
    else if (a < b)
    {
        ll ans;
        ans = (a + (n + 1) * b) - ((n + 1) * a + b) + 1;
        cout << ans << endl;
    }
}


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

int main() {

    string S , T;
    cin >> S >> T ;

    int a = 0;

    for(int i=0 ; i<S.size() ; i++){

        if(S.at(i)==T.at(i)){
            a++;
        }

    }

    if(a==S.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int s,i=1,m;
    cin>>s;
    m=s;
	while(s!=4){
		if(m==2 || m==1) break;
		if(s%2==0){
			s/=2;
		}else s=3*s+1;
		i++;
	}
	cout <<i+3<<endl;
	return 0;
}

Measured memory_bytes: 256
a, b, c = gets.split.map(&:to_i)
s = 0.5 * a * b * Math.sin(c * Math::PI / 180)
l = a + b + (a**2 + b**2 - 2 * a * b * Math.cos(c * Math::PI / 180)) **0.5
h = 2 * s / a
puts [s.round(5),l.round(5),h.round(5)]


Measured memory_bytes: 6964
#include<stdio.h>
int main(void)
{
int a,b,c,d;
d=0;
scanf("%d%d%d",&a,&b,&c);
if(a<b){
d+=1;
}
if(b<c){
d+=1;
}
if(d==2){
printf("Yes\n");
}
if(d<2){
printf("No\n");
}
return 0;
}

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

int main() {
  int D, N;
  cin >> D >> N;
  if (D == 0) {
    if (N == 100) {
      cout << 101 << endl;
    }
    else {
      cout << N << endl;
    }
  }
  else if (D == 1) {
    if (N == 100) {
      cout << 10100 << endl;
    }
    else {
      cout << N*100 << endl;
    }
  }
  else if (D == 2) {
    if (N == 100) {
      cout << 1010000 << endl;
    }
    else {
      cout << N*10000 << endl;
    }
  }
}


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

int main(){
    string s;
    cin >> s;
    map<string, int> ans;
    ans["SUN"] = 7;
    ans["MON"] = 6;
    ans["TUE"] = 5;
    ans["WED"] = 4;
    ans["THU"] = 3;
    ans["FRI"] = 2;
    ans["SAT"] = 1;
    cout << ans[s] << endl;

    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $n, $k);
$a = explode(' ', trim(fgets(STDIN)));

$c = array_count_values($a);
arsort($c);
$d = count($c) - $k;
$x = 0;
for ($i = 0; $i < $d; $i++) {
	$x += array_pop($c);
}
echo $x;

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

int main(){
  int N; cin >> N;
  string str; cin >> str;
  long long r = 0, g = 0, b = 0;
  for (int i = 0; i < N; i++){
    if (str[i] == 'R') r++;
    if (str[i] == 'G') g++;
    if (str[i] == 'B') b++;
  }
  long long all = r * g * b;
  
  long long sub = 0;
  for (int i = 0; i < N - 1; i++){
    for (int j = i + 1; j < N; j++){
      if (str[i] == str[j]) continue;
      if (2 * j - i < N){
        if (str[i] == str[2 * j - i] || str[j] == str[2 * j - i]) continue;
        sub += 1;
      }
    }
  }
  cout << all -sub << endl;
  return 0;
}

Measured memory_bytes: 3628
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskT solver = new TaskT();
        solver.solve(1, in, out);
        out.close();
    }
    
    

    static class TaskT {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	int ans = 0;
        	int N = in.nextInt();
        	int[] arr = new int[N];
        	for(int i = 0; i < N ; i ++)
        		arr[i] = in.nextInt();
        	
        	for(int i = 0; i < N ; i++){
        		for(int j = i+1; j < N; j++){
        			for(int k = j+1; k < N; k++){
        				if(arr[i] != arr[j] && arr[j]!= arr[k] && arr[k]!= arr[i]){
        					
        					if(arr[i]+arr[j] >arr[k]&& arr[j]+arr[k] > arr[i] && arr[k]+arr[i] > arr[j]){
        						ans++;
        					}
        					
        				}
        			}
        		}
        	}
        	out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 32972
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 N;
    cin>>N;
    double ans=0;
    vector<double> A(N);
    for(int64 i=0;i<N;i++){
        cin>>A[i];
        ans+=1.0/A[i];
    } 

    ans=1.0/ans;
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int k; cin>>k;
	queue <ll> q;
	for(ll i=1;i<=9;i++) q.push(i);
	for(int i=0;i<k-1;i++)
	{
	    ll j=q.front();
	    q.pop();
	    ll tt=10*j + j%10;
	    if(j%10!=0) q.push( tt-1 );
	    q.push( tt );
	    if(j%10!=9) q.push( tt+1 ); 
	}
	cout<<q.front();
	
	
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> v(n);
  REP(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  vector<queue<ll>> vh(2);
  queue<P> que;

  vector<bool> visited(n, false);

  que.push(P(0, 0));
  while (!que.empty()) {
    ll now = que.front().first;
    ll h = que.front().second;
    que.pop();
    visited[now] = true;
    vh[h % 2].push(now);

    for (auto x : v[now]) {
      if (visited[x]) continue;
      que.push(P(x, h + 1));
    }
  }

  map<ll, ll> mp;
  ll m0 = 3, m1 = 1, m2 = 2;
  if (vh[0].size() > n / 3 && vh[1].size() > n / 3) {
    while (!vh[0].empty()) {
      ll now = vh[0].front();
      vh[0].pop();
      if (m1 <= n) {
        mp[now] = m1;
        m1 += 3;
      } else {
        mp[now] = m0;
        m0 += 3;
      }
    }
    while (!vh[1].empty()) {
      ll now = vh[1].front();
      vh[1].pop();
      if (m2 <= n) {
        mp[now] = m2;
        m2 += 3;
      } else {
        mp[now] = m0;
        m0 += 3;
      }
    }

  } else {
    if (vh[0].size() <= n / 3) {
      while (!vh[0].empty()) {
        ll now = vh[0].front();
        vh[0].pop();
        mp[now] = m0;
        m0 += 3;
      }

      while (!vh[1].empty()) {
        ll now = vh[1].front();
        vh[1].pop();
        if (m1 <= n) {
          mp[now] = m1;
          m1 += 3;
        } else if (m2 <= n) {
          mp[now] = m2;
          m2 += 3;
        } else {
          mp[now] = m0;
          m0 += 3;
        }
      }

    } else {
      while (!vh[1].empty()) {
        ll now = vh[1].front();
        vh[1].pop();
        mp[now] = m0;
        m0 += 3;
      }

      while (!vh[0].empty()) {
        ll now = vh[0].front();
        vh[0].pop();
        if (m1 <= n) {
          mp[now] = m1;
          m1 += 3;
        } else if (m2 <= n) {
          mp[now] = m2;
          m2 += 3;
        } else {
          mp[now] = m0;
          m0 += 3;
        }
      }
    }
  }
  REP(i, n) { cout << mp[i] << " "; }
  return 0;
}


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

int main(){
  long long n,i,j,k,ret;
  cin >> n;
  ret = 1;
  for(i=2;i*i<=n;i++){
    if(n%i==0)ret=i;
  }
  ret = max(ret,n/ret);
  int cnt = 0;
  while(ret){
    cnt++;
    ret/=10;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#!ruby -pl
def f a
!a[2]&&a[0]==a[1]||a.combination(3).any?{|p|b,c,d=p.sort
(b==c&&c==d||b+1==c&&c+1==d)&&(e=a.dup;p.map{|i|e.delete_at(e.index i)};f(e))}end
$_=(d=(1..9).select{|i|(l=$_.chars.map(&:to_i)<<i).count(i)<5&&f(l)}*" ")>""?d:0

Measured memory_bytes: 6112
N = int(input())
W_list = list(map(int,input().split()))

T = 0
result_list = []

for i in range(N):
    T = i
    W_list_aaa = W_list[0:i]
    W_list_bbb = W_list[i:]
    result_list.append(abs(sum(W_list_aaa)-sum(W_list_bbb)))

print(min(result_list))





Measured memory_bytes: 3060
A="".join(["11000000",
           "11"])

B="".join(["10000000",
           "10000000",
           "10000000",
           "1"])

C="".join(["1111"])

D="".join(["01000000",
           "11000000",
           "1"])

E="".join(["11000000",
           "011"])

F="".join(["10000000",
           "11000000",
           "01"])

G="".join(["01100000",
           "11"])

teto=[A,B,C,D,E,F,G]



while True:
    try:
        a="".join([raw_input() for i in xrange(8)])
        for i in range(len(teto)):
            if a.find(teto[i])>=0:
                print chr(i+ord("A"))
        raw_input()
    except:
        break

Measured memory_bytes: 23000
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+100;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int y[x];
    ll sum=0;
    for (int i=0;i<x;i++){
        cin>>y[i];
        sum+=y[i];
    }
    sort(y,y+x);
    sum-=y[x-1]/2;
    cout<<sum<<endl;
    return 0;
}


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

bool b(char ch){
  string k="yuiophjklnm";
  for(int i=0;i<(int)k.size();i++)
    if(k[i]==ch) return 1;
  return 0;
}

int main(){
  string s;
  while(cin>>s && s!="#"){
    int ans=0;
    bool f=b(s[0]);
    for(int i=1;i<(int)s.size();i++){
      if(f!=b(s[i])){ans++;f=!f;}
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    char[] x = a.toCharArray();
    char[] y = b.toCharArray();

    if (x[0] > y[0]) {
      System.out.println(">");
    } else if (x[0] < y[0]) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
  }

}


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

int main(){
  int n;
  cin >> n;
  bool flag=true;
  int x,y=0;
  for (int i=0; i<n; i++){
    cin >> y;
    if(x <= y-1){
      x = y-1;
    } else if(x == y){
      x = y;
    } else {
      flag = false;
      break;
    }
  }
  if (flag){
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ans, a, b, c, n, q, num[100005];

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) {
		cin >> a;
		ans += a;
		num[a]++;
	}
	cin >> q;
	FOR(i, 1, q) {
		cin >> b >> c;
		ans += (c-b) * num[b];
		num[c] += num[b];
		num[b] = 0;
		cout << ans << "\n";
	}
}


Measured memory_bytes: 4364
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;

int n, k;
int s[105] = {0};
int main()
{
    cin >> n >> k;
    while(k--)
    {
        int d;
        cin >> d;
        while(d--)
        {
            int a;
            cin >> a;
            s[a]++;
        }
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        cnt += s[i] == 0;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100;
 
int n,q;
int a[maxn],m,num;
 
bool solve(int i,int m)
{
    bool res;
    if(m == 0) return true;
    if(i >= n) return false;
 
   // cout << i << " " << m << " " <<res <<endl;
    res = solve(i+1,m) || solve(i+1,m-a[i]);
    return res;
}
 
int main()
{
    scanf("%d",&n);
    fill(a,a + n, 0);
    for(int i = 0; i < n; ++i) scanf("%d",&a[i]);
    scanf("%d",&q);
    sort(a,a+n);
    for(int i = 0; i < q; ++i){
        scanf("%d",&m);
        if(solve(0,m)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 3184
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll times = x/d;
    if (k <= abs(times)) {
        cout << x - d*k << endl;
        return 0; 
    }
    if ((k-times)%2==0) {
        cout << x%d << endl;
    } else {
        cout << abs(x%d - d) << endl;
    }
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
using ll=long long;
const ll INF=1e18;
typedef pair<int,int> C;
typedef pair<ll,int> P;
map<P,ll> G;
vector<int> V[100005];
ll d[100005];
void dijkstra(int s) {
    priority_queue<P,vector<P>,greater<>>que;
    for(int i=0;i<100001;i++) 
		d[i]=INF;
    d[s]=0;
    que.push(P(0,s));
    while (!que.empty()){
        P p=que.top();
		que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for (auto to:V[v]){
            ll cost=G[C(v,to)];
            if (d[to]>d[v]+cost){
                d[to]=d[v]+cost;
                que.push(P(d[to],to));
            }
        }
    }
}
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;
        ll c;
        cin>>a>>b>>c;
        a--; 
		b--;
        G[C(a,b)]=c;
        G[C(b,a)]=c;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    int Q,K;
    cin>>Q>>K;
    K--;
    dijkstra(K);
    for(int i=0;i<Q;i++){
        int x,y;
        cin>>x>>y;
        x--; 
		y--;
        cout<<d[x]+d[y]<<endl;
    }
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N;
  vector<llong> L;

  cin >> N;
  L.resize(N);
  for (auto &in: L) {
    cin >> in;
  }
  sort(ALL(L));

  llong ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int k = j + 1; k < N; k++) {
        if (L[i] == L[j] || L[j] == L[k]) continue;
        ans += L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i];
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

int N,K;
string S;

signed main(){
    cin>>N>>K;
    cin>>S;
    S[K-1]+=32;
    cout<<S<<endl;
}

Measured memory_bytes: 3512
// abc128_a
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
struct  Struct
{
	int id;
	string name;
	int val;
	Struct(int i, string n, int v) {
		id = i;
		name = n;
		val = v;
	}

	bool operator < (const Struct& another) const {
		if (name != another.name) {
			return name < another.name;
		}
		else {
			return val > another.val;
		}
	};
};

int main(void) {
	int N;
	cin >> N;
	vector<Struct> vec;
	for (int i = 0; i < N; i++) {
		string name;
		int value;
		cin >> name >> value;
		vec.push_back(Struct(i + 1, name, value));
	}
	sort(vec.begin(),vec.end());
	for (int i = 0; i < N; i++) {
		cout << vec[i].id << endl;
	}

	return 0;
}

Measured memory_bytes: 256
"""
int(input())
map(int,input().split())
list(map(int,input().split()))

"""

def is_pal(s):
    if(s==s[::-1]):
        return True
    else:
        return False
        
s=input()
if is_pal(s):
    n=len(s)//2
    if is_pal(s[0:n]) and is_pal(s[n+1:]):
        print("Yes")
    else:
        print("No")
    
else:
    print("No")

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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e12

int const N = 1e5+5;

int vak[N];

int main()
{
    int n, k , q; cin >> n >> k >> q;
    //0 se erra
    //+1 se acerta
    for (int i = 0; i < q; i++)
    {
        int a; cin >> a;
        vak[a]++;
    }

    for (int i = 1; i <= n; i++)
    {
        if (k - q + vak[i] > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
def main():
    N, X = map(int, input().split())
    dx = [abs(X - x) for x in map(int, input().split())]
    if N == 1:
        ans = dx[0]
    else:
        ans = 10 ** 9
    for i in range(N - 1):
        nm = max(dx[i], dx[i + 1])
        dm = min(dx[i], dx[i + 1])
        while True:
            mod = nm % dm
            if mod == 0:
                break
            nm = dm
            dm = mod
        ans = min(ans, dm)
    print(ans)


main()


Measured memory_bytes: 14252
n = gets.to_i
a = Array.new(360, 0)
n.times do
    m, d, v, s = gets.split.map(&:to_i)
    from = 30 * (m - 1) + (d - 1)
    to = (from + v - 1) % 360
    i = from
    loop do
        j = i % 360
        dist =  from - i
        break if j == to || dist == s
        a[j] = s - dist if a[j] < s - dist
        i -= 1
    end
    i = to
    loop do
        j = i % 360
        dist = i - to
        break if j == from || dist == s
        a[j] = s - dist if a[j] < s - dist
        i += 1
    end
    i = from
    loop do
        j = i % 360
        a[j] = s if a[j] < s
        break if j == to
        i += 1
    end
end
p a.min



Measured memory_bytes: 6892
# include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,w;
    cin>>n>>w;
    int wt[n+1] = {0},vl[n+1] = {0};
    
    for(int i = 0;i<n;i++)
    {
        cin>>wt[i]>>vl[i];
    }
    long long dp[w+1] = {0};
    for(int i = 0;i<n;i++)
    {
        for(int j = w;j>=wt[i];j--)
        {
            dp[j] = max(dp[j],dp[j - wt[i]] + vl[i]);
        }
    }
    cout<<dp[w]<<'\n';

}

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

int main()
{
  int n, i, a[100];
  int a_sum, b_sum;
  
  a_sum = b_sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a+n);
  for (i = n-1; i >= 0; i -= 2) {
    a_sum += a[i];
  }
  for (i = n - 2; i >= 0; i -= 2) {
    b_sum += a[i];
  }
  cout << a_sum - b_sum << endl;
  return 0;
}

Measured memory_bytes: 256