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

using namespace std;

#define ops cout<<"ops"<<endl;
#define freopens freopen("cowpatibility.in", "r", stdin);freopen("cowpatibility.out", "w", stdout);
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define DIM 107
#define DIMM 100007
#define INF 10000000000000000007.0
#define X 31
#define eps 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO (long long)1000000007

const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll n,W,res;
ll w[DIM],v[DIM];
ll dp[DIM][DIMM];

int main()
{
    //ops;
    //freopens;
    fast;
    //ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

    cin>>n>>W;
    for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
    for(int i=1;i<=n;i++){
     for(int j=0;j<=W;j++){
      dp[i][j]=dp[i-1][j];
      if(j>=w[i] && dp[i][j]<(dp[i-1][j-w[i]]+v[i]))dp[i][j]=dp[i-1][j-w[i]]+v[i];
     }
    }
    for(int j=0;j<=W;j++)res=max(res,dp[n][j]);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 79360
//Author : Vipul Sharma
 
// LIBRARIES

#include<iostream>
#include<set>
#include<algorithm>
#include<map>
#include <bits/stdc++.h>
 
// MACROS
#define ll long long int
#define ld long double
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rev(i,b,a) for(ll i=b-1;i>=a;i--)
#define eqrep(i,b) for(ll i=1;i<=b;i++)
#define itrep(at) for (auto it = at.begin(); it != at.end(); it++)
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ipair pair<ll,ll>
#define umap unordered_map<ll,ll>
#define map map<ll,ll>
#define w(t) while (t--)
#define booster                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define deb1(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << endl;
#define deb4(x, y, z, w) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << "\t" << #w << " : " << w << endl;
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define deb6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
using namespace std;
long long cost = 1e18;
 
 
 
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	booster;
	ll n,total_legs;
	cin>>n>>total_legs;
	bool flag=true;
	for(ll i=0;i<=total_legs/2;i++)
	{
		for(ll j=0;j<=total_legs/4;j++)
		{
			if(i+j==n&&(2*i+4*j)==total_legs)
			{
				flag=false;
			}
		}
	}
	if(!flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=5000+5;
const int mod=1e9+7;
ll dp[maxn][maxn];
inline ll fastpow(ll a,ll b) {
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod) if(b&1) ans=ans*a%mod;
	return ans;
}
int main() {
    int n,k;cin>>n;string s;cin>>s;k=s.length();
    dp[0][0]=1;
    for(int i=1;i<=n;i++) {
    	dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod;
    	for(int j=1;j<=i;j++) {
    		dp[i][j]=(dp[i-1][j+1]+dp[i-1][j-1]*2)%mod;
    	}
    }
    cout<<dp[n][k]*fastpow(fastpow(2,k),mod-2)%mod<<endl;
    return 0;
}

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

int main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	bool flag[20];
	memset(flag, false, sizeof(flag));
	int k;
	int n;
	cin >> n >> k;
	for (int i = 0; i < k; i++)
	{
		int a;
		cin >> a;
		flag[a] = true;
	}
	bool kkk = true;
	for (int i = n; ; i++)
	{
		kkk = true;
		int ans = i;
		while (ans)
		{
			if (flag[ans % 10])
			{
				kkk = false;
				break;
			}
			ans = ans / 10;
		}
		if (kkk)
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll n,a,b,ans=0;cin>>n>>a>>b;
  vll x(n);
  rep(i,0,n){cin>>x[i];}
  rep(i,0,n-1){
    if((x[i+1]-x[i])*a>b)ans+=b;
    else ans+=(x[i+1]-x[i])*a;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4028
#!/usr/local/bin/python3

import math

def power(P, X):
    ans = 0
    for x in X:
        ans += (x-P)**2
    return ans

N = int(input())
X = list(map(int, input().split()))
ave = sum(X)/N
candP = (math.ceil(ave), math.floor(ave))
power = min(map(lambda P: power(P, X), candP))

print(power)


Measured memory_bytes: 9184
from sys import stdin
import sys
import math


A, B, H, M = [int(x) for x in stdin.readline().rstrip().split()]
h = 30*H+M/60*30
m = 6*M
temp = abs(h-m)
if 360-temp < temp:
    temp = 360-temp
ans = A*A+B*B-2*A*B*math.cos(math.radians(temp))
print(math.sqrt(ans))


Measured memory_bytes: 9500
#include<iostream>
using namespace std;
int main() {
	int N, K, sum = 0;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		if (x < K - x)
			sum += x;
		else
			sum += K - x;
	}
	cout << sum * 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int n, k, c;

vector<int> sub(string s){
    int n = s.size();
    int cur = 0; 
    int last = - c - 1;
    vector<int> res(n+1, 0);
    for(int i = 0; i < n; i++){
        if(i > last + c && s[i] == 'o') ++cur, last = i;
        res[i+1] = cur;
    }
    return res;
}

int main(){
    cin >> n >> k >> c;
    string s; cin >> s;
    auto left = sub(s);
    string t = s;
    reverse(ALL(t));
    auto right = sub(t);
    for(int i = 0; i < n; i++){
        if(s[i] == 'x') continue;
        if(left[i] + right[n-i-1] < k) cout << i+1 << endl;
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  while(true){
  int n,m;
  cin >> n >> m;
  if (n==0) break;
  vector<int> a(n,0);
  rep(i,n){
    int f,g;
    cin >> f >> g;
    a[f-1]=max(g,a[f-1]);
  }
  int ans=0;
  rep(i,n){
    ans+=a[i];
  }
  cout << ans << endl;
  }
}



Measured memory_bytes: 3088
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>

using namespace std;

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

  int n = N % 10;
  switch (n) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
        
  }

  return 0;
}
 


Measured memory_bytes: 3100
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

class TaskA {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n; in>>n;
        ll arr[n+1], res = 0;
        arr[0] = 0;
        map<ll, ll> m;
        m[0] = 1;
        for(int i = 0; i<n; ++i) in>>arr[i+1], arr[i+1]+=arr[i], res += m[arr[i+1]], m[arr[i+1]]++;
        out<<res;
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	TaskA solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <complex>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
const double EPS = 1e-9;

typedef unsigned long long ull;
typedef std::complex<double> P;

namespace std{
    bool operator<(const P& lp, const P& rp){
        if(real(lp) != real(rp)){
            return real(lp) < real(rp);
        }
        return imag(lp) < imag(rp);
    }
}    

double dot(const P& lp, const P& rp){
    return real(lp)*real(rp)+imag(lp)*imag(rp);
}

double cross(const P& lp, const P& rp){
    return real(lp)*imag(rp)-imag(lp)*real(rp);
}

int ccw(P a, P b, P c){
    b -= a; c -= a;
    if(cross(b, c) > 0)return 1; // counter clock wise
    if(cross(b, c) < 0)return -1; // clock wise
    if(dot(b, c) < 0)return 2; // B A C
    if(norm(b) < norm(c))return -2; // A B C
    return 0; // A C B
}

std::vector<P> convex_hull(std::vector<P> ps){
    int n = ps.size(), k = 0;
    std::sort(ps.begin(), ps.end());

    std::vector<P> ch(2*n);
    for(int i=0;i<n;ch[k++]=ps[i++]){ // 下
        while(k>=2&&ccw(ch[k-2], ch[k-1], ps[i])<=0){--k;} // 反時計になるよう調整
    }
    for(int i=n-2, t=k+1;i>=0;ch[k++]=ps[i--]){ // 上
        while(k>=t&&ccw(ch[k-2], ch[k-1], ps[i])<=0){--k;}
    }
    
    ch.resize(k-1); // 輪を閉じる部分(最初と最後)の重複を除く
    return ch;
}

int main(){
    int N;
    while(std::cin >> N, N){
        std::vector<P> Nails;
        REP(i, N){
            double x, y;
            scanf("%lf,%lf", &x, &y);
        
            Nails.push_back({x, y});
        }

        auto ch = convex_hull(Nails);

        std::cout << N - ch.size() << std::endl;
    }
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
	cin>>a[i];
  }
  int f=0,count=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]%2==0)
    { //f=0;
      count++;
      if(a[i]%3==0 || a[i]%5==0)
      {
        f++;
      }
    }
  }
  if(count!=f)
    cout<<"DENIED";
  else
    cout<<"APPROVED";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
 
vector <string> brackets;
int n;
 
bool cmp(string a, string b){
  pair <int,int> cnta = {0,0};
  pair <int,int> cntb = {0,0};
  int n = a.size();
  int m = b.size();

  for(int i=0;i<n;i++)
    if(a[i] == '(')
      cnta.first++;
    else
      cnta.second++;
  for(int i=0;i<m;i++)
    if(b[i] == '(')
      cntb.first++;
    else
      cntb.second++;

  int difa = cnta.first- cnta.second;
  int difb = cntb.first - cntb.second;

  if(difa >= 0 && difb < 0) return true;
  if(difb >= 0 && difa < 0) return false;
  if(difa >= 0 && difb >= 0) return cnta.second < cntb.second;
  return cnta.first > cntb.first;
}
 
bool solve(){
  stack <char> s;
 
  for(int i=0;i<n;i++){
    int m = brackets[i].size();
    for(int j=0;j<m;j++){
      char cur = brackets[i][j];
      if(cur == '(')
        s.push(cur);
      else if(!s.empty())
        s.pop();
      else return false;
    }
  }
 
  return s.size() == 0;
}
 
int main(){
 
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  
  cin >> n;
  brackets.resize(n);
 
  for(int i=0;i<n;i++)
    cin >> brackets[i];
 
  sort(brackets.begin(),brackets.end(),cmp);
 
  if(solve()){
    cout << "Yes" << endl;
  }else
    cout << "No" << endl;
 
 
 
  
  return 0;
}

Measured memory_bytes: 34792
#import<cstdio>
int main(){int a,c=1,r=1;for(char d[]="123546",s[9];a=scanf("%s",s),*s>60;r+=*d%8)*s%6-4?a=*s%5+*s%2*2+c&3,d[++a]=d[5],d[5]=d[a=++a%4+1],d[a]=*d,*d=55-d[5]:c+=*s+3;~-r&&printf("%d\n",r);~a&&main();}

Measured memory_bytes: 0
import numpy as np

N, M = map(int, input().split())
A = []

for i in range(0, N):
    a, b = np.array(list(map(float, input().split())))
    A.append((a, b))

dtype = [('key', int), ('value', int)]
arrayA = np.array(A, dtype=dtype)
arrayA = np.sort(arrayA, order=['key'])
cnt = 0
sum = 0
flag = 0
for j in range(0, N):
    pay = arrayA[j][0]
    num = arrayA[j][1]
    if cnt + num < M :
        cnt += num
        sum += pay*num
    else :
        diff = int(M - cnt)
        for t in range(0, diff):
            sum += pay
            cnt += 1
            if cnt == M :
                flag = 1
                print(int(sum))
                break
    if flag == 1:
        break

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

int main(void){
  int h,w;
  cin >> h >> w;
  string board[50];
  
  for(int i = 0; i < h; i++) cin >> board[i];
  
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(board[i][j] == '#') continue;
      
      int num=0;
      for(int d = 0; d < 8; d++){
      	const int ni = i + dy[d];
        const int nj = j + dx[d];
        
        if(ni < 0 or h <= ni) continue;
        if(nj < 0 or w <= nj) continue;
        if(board[ni][nj] == '#') num++;
      }
      board[i][j] = char(num + '0') ;
    }
  }
  for (int i = 0; i < h; ++i) cout << board[i] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <complex>
#include <queue>
#include <deque>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
typedef complex<int> cl;
typedef pair<cl,cl> pr;
typedef pair<pr,int> ppr;
typedef vector<pr> vpr;
const int INF=1<<30;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
bool reached[52][52][52][52]={};
ppr pprs(cl a,cl b,int c){ return ppr(pr(a,b),c);}
int main() {
	// your code goes here
	int X,Y,tmp,tmpb;
	while(cin >> X >> Y && X){
	REP(i,52) REP(j,52) REP(k,52) REP(l,52) reached[i][j][k][l]=false;
	bool maps[52][52]={};
	cl t,k;
	cin >> tmp>> tmpb;
	t=cl(tmpb,tmp);
	cin >> tmp>> tmpb;
	k=cl(tmpb,tmp);
	REP(i,Y+2)
		REP(j,X+2)
				maps[i][j]=1;
	FORE(i,1,Y)
		FORE(j,1,X)
			cin >> maps[i][j];
	queue<ppr> qu;
	qu.push(pprs(t,k,0));
	int ans=-1;
	while(!qu.empty()){
		cl a=qu.front().first.first,b=qu.front().first.second;
		int t=qu.front().second;
		qu.pop();
		if(a==b){
			ans=t;
			break;
		}
		if(reached[a.real()][a.imag()][b.real()][b.imag()]) continue;
		reached[a.real()][a.imag()][b.real()][b.imag()]=1;

		REP(i,4){
			
			cl na=cl(a),nb=cl(b);
			if(!maps[a.real()+dy[i]][a.imag()+dx[i]])
				na+=cl(dy[i],dx[i]);
			if(!maps[b.real()-dy[i]][b.imag()-dx[i]])
				nb-=cl(dy[i],dx[i]);
			if(!reached[na.real()][na.imag()][nb.real()][nb.imag()])
			qu.push(pprs(na,nb,t+1));
		}
	}
	if(ans==-1 || ans>=100)
	cout << "NA" << endl;
	else 
	cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 8828
#include<stdio.h>
int main(){
	int a,b,n,m;
	for(;;){
		if(scanf("%d",&a)==EOF){break;}
		scanf("%d",&b);
		n=a+b;
		m=1;
		while(n>=10){
			n=n/10;
			m++;
		}
		printf("%d\n",m);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] buff=new int[n];
		int sum=0;

		for(int i=0;i<n-1;i++) {
			buff[i]=sc.nextInt();
		}
		buff[n-1]=Integer.MAX_VALUE;
		for(int i=1;i<n;i++) {
			sum+=Math.min(buff[i-1],buff[i]);
			//System.out.println(sum);
		}
		System.out.println(sum+buff[0]);
	}
}



Measured memory_bytes: 23124
import java.util.Comparator
fun main(arg: Array<String>) {
    val N = nextInt()
    val A = listOfInt().sorted()
    val B = listOfInt()
    val C = listOfInt().sorted()
    var ans = 0L
    for (b in B) {
        val a = A.lowerBound(b)
        val c = C.upperBound(b)
        ans += 1L * a * (N - c)
    }
    println(ans)
}
//lowerBound関数は指定した値以上の要素が最初に現れる位置
fun List<Int>.lowerBound(n: Int) = this.binarySearch(n, Comparator { x, y -> if (x.compareTo(y) >= 0) 1 else -1 }).inv()
//upperBound関数は指定した値より大きいの要素が最初に現れる位置
fun List<Int>.upperBound(n: Int) = this.binarySearch(n, Comparator { x, y -> if (x.compareTo(y) >  0) 1 else -1 }).inv()

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { Integer.parseInt(it) + d }
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 98656
from collections import deque
import numpy as np


def bfs(N, u, path):
    d = [-1] * N
    d[u-1] = 0
    q = deque([])
    q.append(u-1)

    while(len(q) != 0):
        p = q.popleft()

        rs = path[p]

        for r in rs:
            if d[r] == -1:
                d[r] = d[p] + 1
                q.append(r)

    return d


def bfs2(N, u, path, d):
    e = [-1] * N
    e[u-1] = 0
    q = deque([])
    q.append(u-1)
    far_p = u-1

    while(len(q) != 0):
        p = q.popleft()

        if (d[p] - e[p]) >= 1:
            rs = path[p]

            is_end = len(rs)
            for r in rs:
                if e[r] == -1:
                    e[r] = e[p] + 1
                    q.append(r)
                else:
                    is_end -= 1

            if is_end == 0:
                if d[p] >= d[far_p]:
                    far_p = p

    return e, far_p


N, u, v = map(int, input().split())
path = [[] * N for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a = a-1
    b = b-1
    path[a].append(b)
    path[b].append(a)

d = bfs(N, v, path)
e, far_p = bfs2(N, u, path, d)

print(d[far_p]-1)


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

#define REP(i, a, b) for (int i = a; i < b; ++i)
#define MOD 1000000007
#define nline cout << "\n";
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int lli;
typedef vector<int> vi;
typedef vector<lli> vlli;

typedef pair<int, int> pi;
typedef pair<lli, lli> plli;

typedef vector<pi> vpii;
typedef vector<plli> vplli;

int countd(int n)
{
    int x = sqrt(n);
    int c = 0;
    for (int i = 1; i <= x; i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                c++;
            else
                c += 2;
        }
    }
    return c;
}
lli cnt[10000000 + 5];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        lli sum = 0;
        for (lli i = 1; i <= n; i++)
        {
            for (lli j = i; j <= n; j += i)
            {
                cnt[j]++; //// here cnt[x] means count of divisors of x
            }
        }
        for (lli i = 1; i <= n; i++)
        {
            sum += i * cnt[i];
            // cout << cnt[i] << " ";
        }

        cout << sum;
    }

    return 0;
}


Measured memory_bytes: 81784
import java.util.Arrays;
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int[] s = new int[n];
			int sum = 0;
			int min = 0;
			boolean flg = true;
			
			for(int i=0;i<n;i++) {
				s[i] = sc.nextInt();
				sum+=s[i];
			}
			
			if(sum%10!=0) {
				System.out.println(sum);
				return;
			}
			
			Arrays.sort(s);
			
			for(int i=0;i<n;i++) {
				if(s[i]%10!=0) {
					min=s[i];
					flg = false;
					break;
				}
			}
			
			if(flg) {
				System.out.println(0);
			}else {
				System.out.println(sum-min);
			}
			
			
		}
	}

Measured memory_bytes: 22996
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of jonathanirvings' template v3.0.3 (BETA)

string s;

int main()
{
  s = GetString();
  printf("%s %s\n",s.substr(0,4).c_str(),s.substr(4,8).c_str());
  return 0;
}










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

template <typename Map>
void print_map(const Map &c, const std::string &name)
{
  std::cout << name << ": ";
  std::for_each(c.begin(), c.end(),
                [](auto &x) { std::cout << x.first << "->" << x.second << ", "; });
  std::cout << std::endl;
}

template <typename C>
void print_container(const C &c, const std::string &name)
{
  std::cout << name << ": ";
  std::for_each(c.cbegin(), c.cend(),
                [](auto &x) { std::cout << x << ", "; });
  std::cout << std::endl;
}

void shrink(
    std::multimap<std::string, int> &lut,
    std::set<std::string> &lut_uniq,
    size_t k)
{
  bool deletes = false;
  std::string last_str = "";
  for(auto it=lut.begin(); it!=lut.end(); ) {
    if(deletes && it->first != last_str) {
      it = lut.erase(it);
    } else {
      lut_uniq.insert(it->first);
      if(lut_uniq.size() == k) {
        deletes = true;
        last_str = it->first;
      }
      it++;
    }
  }
}

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

  int len = (int)s.size();

  // substr vs pos
  std::multimap<std::string, int> lut[K];
  std::set<std::string> lut_uniq[K];

  for(int i=0; i<len; i++) {
    lut[0].insert(std::make_pair(s.substr(i, 1), i));
  }
  // print_map(lut[0], "lut[0]");
  shrink(lut[0], lut_uniq[0], K);
  // print_container(lut_uniq[0], "lut_uniq[0]");

  for(int i=1; i<(int)K; i++) {
    for(auto it: lut[i-1]) {
      if(it.second <= len-(i+1)) {
        lut[i].insert(std::make_pair(s.substr(it.second, i+1), it.second));
      }
    }
    // print_map(lut[i], "lut[" + std::to_string(i) + "]");
    shrink(lut[i], lut_uniq[i], K);
    // print_container(lut_uniq[i], "lut_uniq[" + std::to_string(i) + "]");
  }

  std::set<std::string> substr;
  for(int i=0; i<(int)K; i++) {
    for(auto a: lut[i]) {
      substr.insert(a.first);
    }
  }
  auto it = substr.begin();
  // print_container(substr, "substr");

  std::cout << *(std::next(it, K-1)) << std::endl;
  return 0;
}


Measured memory_bytes: 5572
a1,a2,b1,b2,c1,c2,d1,d2 =0,0,0,0,0,0,0,0
while True:
  try:
    q,w = map(float,raw_input().split())
    if q >= 1.1: a1+=1
    if w >= 1.1: a2+=1
    if 1.1 > q >= 0.6: b1+=1
    if 1.1 > w >= 0.6: b2+=1
    if 0.6 > q >= 0.2: c1+=1
    if 0.6 > w >= 0.2: c2+=1
    if q < 0.2:d1+=1
    if w < 0.2:d2+=1
  except EOFError: break
if __name__ == '__main__':
  print a1,a2
  print b1,b2
  print c1,c2
  print d1,d2

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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int K = cin.nextInt();
        int[] h = cin.arrayInt();
        long[] DP = new long[N];

        for (int i = 0; i < N; i++)
        {
            DP[i] = 10000000000;
        }

        DP[0] = 0;

        for (int i = 0; i < N; i++)
        {
            for (int j = 1; j <= K; j++)
            {
                if (i + j < N)
                {
                    DP[i + j] = Math.Min(DP[i + j], DP[i] + Math.Abs(h[i] - h[i + j]));
                }
            }
        }

        Console.WriteLine(DP[N - 1]);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



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

int main() {
	string s;
    cin >> s;
    for (int i = 0; i < 3; i++) {
        if (s[i] == s[i+1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
	return 0;
}


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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int M1, D1, M2, D2; cin >> M1 >> D1 >> M2 >> D2;
  if (D2 == 1) {
    cout << 1 << endl;
  }else {
    cout << 0 << endl;
  }

  return 0;
}



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

int main() {
	ios_base::sync_with_stdio( false );

	vector<int> a( 3 );
	cin >> a[0] >> a[1] >> a[2];
	sort( a.begin(), a.end() );
	cout << a[0] + a[1] + 10*a[2] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int N;
	cin>>N;
	vector<int>arr(N);
	for(int i=0; i<N; i++)
	 cin>>arr[i];
	int flag=0;
	for(int i=0; i<N; i++){
		if(arr[i]%2==0)
		{
			if(arr[i]%3!=0 && arr[i]%5!=0)
			{
				flag=1;
				break;
			}
		}
	}
	if(flag)
	 cout<<"DENIED";
	else
	 cout<<"APPROVED";
	return 0;
	
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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

int dp[808][808];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,k;
    cin>>h>>w>>k;
    string a[h];
    REP(i,h) cin>>a[i];
    int sy,sx;
    REP(i,h) REP(j,w) if(a[i][j]=='S') sy=i,sx=j;

    int ans=800000;
    memset(dp,-1,sizeof(dp));

    queue<P> q;
    q.push({sy,sx});
    dp[sy][sx]=0;
    while(!q.empty()){
        auto p=q.front();q.pop();
        int y = p.first;
        int x = p.second;
        if(y==0||y==h-1||x==0||x==w-1){
            cout<<1<<endl;
            return 0;
        }
        if(dp[y][x]==k) break;
        REP(i,4){
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(ny<0||ny>=h||nx<0||nx>=w) continue;
            if(a[ny][nx]=='#') continue;
            if(~dp[ny][nx]) continue;
            dp[ny][nx]=dp[y][x]+1;
            q.push({ny,nx});
        }
    }
    REP(i,h) REP(j,w){
        if(dp[i][j]<0||dp[i][j]>k) continue;
        int tmp=(i-1)/k+1;
        tmp=min(tmp,(j-1)/k+1);
        tmp=min(tmp,((h-i)-2)/k+1);
        tmp=min(tmp,((w-j)-2)/k+1);
        ans=min(ans,tmp+1);
    }
    cout<<ans<<endl;
}

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

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for(int i=0; i<M; ++i) cin >> B[i];

    int res = 0;
    for(int i=0; i<N; ++i) {
        int tmp = 0;
        for(int j=0; j<M; ++j) {
            int a;
            cin >> a;
            tmp += a * B[j];
        }
        tmp += C;
        if(tmp > 0) ++res;
    }
    cout << res << endl;
}

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

int main() {
	int N;
	cin >> N;
	map<int, int> Nums;
	int ans = 0, sub=0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		Nums[A]++;
		if (Nums[A] == 2) sub++;
		if (Nums[A] == 3) {
			Nums[A] = 1;
			sub--;
			ans++;
		}
	}
	ans += (sub+1) / 2;
	cout << N - 2 * ans << endl;
}

Measured memory_bytes: 4992
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    ans = 0
    p = 0
    for a in A:
        if p <= a:
            p = a
        else:
            ans += (p - a)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 32188
inp = input().split()
A = int(inp[0])
B = int(inp[1])

result = 0
if A > B:
    result += A
    A -= 1
else:
    result += B
    B -= 1
if A > B:
    result += A
    A -= 1
else:
    result += B
    B -= 1

print(result)

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

int main() {
	int n;
	cin >> n;
	int a[100000], b[100000];
	for (int i = 0;i < n;i++)cin >> a[i] >> b[i];
	int max = 0, ans = 0;
	for (int i = 0;i < n;i++) {
		if (max < a[i]) {
			max = a[i];
			ans = b[i];
		}
	}
	cout << max+ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) {
    int xi; cin >> xi;
    x[i] = xi;
    y[i] = xi;
  }
  sort(y);

  int midi = (n - 1) / 2, mid = y[midi], right = y[midi + 1];

  for (int i = 0; i < n; i++) {
    int z = x[i];
    if (z < mid) outl(right);
    else if (z > mid) outl(mid);
    else if (right == mid) outl(mid);
    else outl(right);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main() {
  int64_t n, m;
  std::cin >> n >> m;
  std::set<int64_t> x;
  for (int64_t i = 0; i < m; i++) {
    int64_t tmp;
    std::cin >> tmp;
    x.insert(tmp);
  }

  if (m <= n) {
    std::cout << 0 << std::endl;
    return 0;
  }

  bool flag = false;
  int64_t before;

  std::multiset<int64_t> d;

  for (const auto i : x) {
    if (flag) {
      d.insert(i - before);
    } else {
      flag = true;
    }
    before = i;
  }
  const auto d_thr_p = std::next(d.cbegin(), m - n - 1);
  int64_t d_thr = *d_thr_p;
  int64_t dup = std::distance(d.find(d_thr), d_thr_p);

  int64_t count = 0;

  int64_t dup_count = 0;
  flag = false;
  int64_t min_x;
  for (const auto i : x) {
    if (flag) {
      const auto dis = i - before;
      if (dis < d_thr) {
      } else if (dis == d_thr) {
        if (dup_count <= dup) {
        } else {
          count += before - min_x;
          min_x = i;
        }
        dup_count++;
      } else {
        count += before - min_x;
        min_x = i;
      }
    } else {
      flag = true;
      min_x = i;
    }
    before = i;
  }
  count += before - min_x;

  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int now=1;
    int res=0;
    for(int i=0;i<n;i++){
        if(a[i]==now){
            now++;
        }else{
            res++;
        }
    }
    if(res==n)cout<<-1<<endl;
    else cout<<res<<endl;
}

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

ll a[100010];
ll n;

bool ok(ll k) {
  ll pre = a[0];
  pre -= k;
  for (int i = 1; i < n; i++) {
    pre = a[i] - pre;
  }
  return pre >= k;
}

void f(ll k) {
  ll pre = a[0];
  pre -= k;
  cout << k;
  for (int i = 1; i < n; i++) {
    cout << " " << pre;
    pre = a[i] - pre;
  }
  cout << endl;
}

void solve() {
  cin >> n;
  REP(i,n) {
    cin >> a[i];
    a[i] *= 2;
  }
  ll l = 0, r = a[0] * 2;
  while (l < r) {
    ll mid = (l + r + 1) / 2;
    if (ok(mid)) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  f(l);
}

int main(int argc, char *argv[]){

  /* Regular */
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }
  
  // /* AOJ */
  // solve();
  return 0;
}

Measured memory_bytes: 2048
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

class UF
{
private:
    int         num;
    vector<int> par;
    vector<int> siz;
public:
    //vector<int> val;
public:
    UF(int n): num(n) {
        par.resize(n);
        siz.resize(n);
        //val.resize(n);
        int i;
        for(i=0; i<n; i++) {
            par[i]=i; siz[i]=1;
            //val[i]=0;
        }
    }
	
    int find(int x) {
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(siz[x]<siz[y]) {
            par[x]=y;
            siz[y]=siz[x]+siz[y];
            //val[y]=val[x]+val[y];
        }
        else {
            par[y]=x;
            siz[x]=siz[x]+siz[y];
            //val[x]=val[x]+val[y];
        }
    }

    bool same(int x, int y) {
        return find(x)==find(y);
    }

    int size(int x) {
        return siz[find(x)];
    }

    int ngroup() {
    //int ngroup( int& ans ) {
        int count=0;
        int i;
        for(i=0; i<num; i++) {
            if(par[i]==i) {
                count++;
                //ans += (val[i]? siz[i]: siz[i]-1);
            }
        }
        return count;
    }
};

char str[50][55];

void solve()
{
    int h, w;
    scanf("%d%d", &h, &w);
    UF uf(h*w+1);
#define P(i,j) ((i)*w+(j))
    int i, j;
    for (i = 0; i < h; i++) {
        scanf("%s", str[i]);
        for (j = 0; j < w; j++) {
            if (str[i][j] == '.') {
                uf.unite(P(i, j), P(h, 0));
            }
            if (j>0 && str[i][j - 1] == '#' && str[i][j] == '#') {
                uf.unite(P(i, j - 1), P(i, j));
            }
        }
    }
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            if (i>0 && str[i-1][j] == '#' && str[i][j] == '#') {
                uf.unite(P(i-1, j), P(i, j));
            }   
        }
    }
    
    int bad = 0;
    for (i = 0; i < h*w; i++) {
        if (uf.find(i) == i) {
            if (uf.size(i) == 1) {
                bad = 1;
            }
        }
    }

    if (bad==0) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



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

using namespace std;

int root[4000];
int getRoot(int v){ return root[v] == -1 ? v : root[v] = getRoot(root[v]); }

vector<vector<long long>> solve(int N, const vector<pair<int, pair<int,int>>>& edge){
	fill(root, root+N, -1);
	vector<vector<pair<int,int>>> g(N);
	long long sum = 0;
	for(auto& e : edge){
		int src = e.second.first;
		int dst = e.second.second;
		int p = getRoot(src);
		int q = getRoot(dst);
		if(p != q){
			sum += e.first;
			root[q] = p;
			g[src].emplace_back(dst, e.first);
			g[dst].emplace_back(src, e.first);
		}
	}
	vector<vector<long long>> res(N, vector<long long>(N, -1));
	for(int i=0;i<N;i++){
		res[i][i] = 0;
		queue<int> qu; qu.push(i);
		while(!qu.empty()){
			int pos = qu.front(); qu.pop();
			for(auto& e : g[pos]){
				int dst = e.first;
				if(res[i][dst] >= 0) continue;
				res[i][dst] = max<long long>(res[i][pos], e.second);
				qu.push(dst);
			}
		}
	}
	for(auto& v : res){
		for(auto& t : v) t = sum - t;
	}
	return res;
}

int main(){
	int N, M;
	while(cin >> N >> M){
		vector<pair<int, pair<int, int>>> edge(M);
		for(auto& p : edge){
			cin >> p.second.first >> p.second.second >> p.first;
			--p.second.first;
			--p.second.second;
		}
		sort(edge.begin(), edge.end());
		auto res = solve(N, edge);
		int Q; cin >> Q;
		for(int i=0;i<Q;i++){
			int s, t; cin >> s >> t;
			cout << res[s-1][t-1] << endl;
		}
	}
}


Measured memory_bytes: 131584
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

class Edge {
public:
  int to;     // 辺の行き先
  int yen; // 辺の重み
  int snuuk;
  Edge(int t, int w1, int w2) : to(t), yen(w1), snuuk(w2) { }
};

using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;// first は最短距離、 second は頂点の番号

void dijkstra(vector<int> &dist,priority_queue<P,vector<P>,greater<P>> &que,Graph &G, int s,bool mode){
  // 初期条件 (頂点 0 を初期ノードとする)
  dist[s] = 0;
  que.push(P(0,s)); // 0 を橙色頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    P p = que.top(); // キューから先頭頂点を取り出す
    int v=p.second;
    que.pop();

    if(dist[v]<p.first) continue;//
    // v から辿れる頂点をすべて調べる
    for (auto &nv : G[v]) {
      if(mode==0){
        if(dist[nv.to]>dist[v]+nv.yen){
          dist[nv.to]=dist[v]+nv.yen;
          que.push(P(dist[nv.to],nv.to));
        }
      }
      else{
        if(dist[nv.to]>dist[v]+nv.snuuk){
          dist[nv.to]=dist[v]+nv.snuuk;
          que.push(P(dist[nv.to],nv.to));
        }
      }
    }
  }
}

signed main() {
  int n,m,s,t;
  cin >> n >> m >> s >> t;
  Graph G(n+1);
  rep(i,m){
    int u,v,a,b;
    cin >> u >> v >> a >> b;
    G[u].push_back(Edge(v,a,b));
    G[v].push_back(Edge(u,a,b));
  }

  // BFS のためのデータ構造
  vector<int> min_yen(n+1, INF); // 全頂点を「未訪問」に初期化
  vector<int> min_snuuk(n+1, INF); // 全頂点を「未訪問」に初期化
  priority_queue<P,vector<P>,greater<P>> yen_que;
  priority_queue<P,vector<P>,greater<P>> snuuk_que;
  dijkstra(min_yen,yen_que,G,s,0);
  dijkstra(min_snuuk,snuuk_que,G,t,1);
  vector<int> cost(n+1,0);
  P costp[n+1];
  for(int i=1;i<=n;i++){
    cost[i]=1000000000000000-min_yen[i]-min_snuuk[i];
    costp[i]=P(cost[i],i);
  }
  sort(costp+1,costp+n+1);
  reverse(costp+1,costp+n+1);
  int index=1;
  rep(i,n){
    if(i<costp[index].second){
      cout << costp[index].first << endl;
    }
    else{
      do{
        index++;
      }while(i>=costp[index].second);
      cout << costp[index].first << endl;
    }
  }
}


Measured memory_bytes: 15736
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int M = scn.nextInt();

		/*
		 * boolean MAP[][] = new boolean[N][N]; for(int i = 0; i < M;i++) { int A =
		 * scn.nextInt()-1, B = scn.nextInt()-1; MAP[A][B] = true; MAP[B][A] = true; }
		 *
		 * ArrayDeque<Integer> PQ = new ArrayDeque<Integer>(); PQ.add(0);
		 *
		 * int[] ans = new int[N]; ArrayList<Integer> remain = new ArrayList<Integer>();
		 * ArrayList<Integer> remain_buf = new ArrayList<Integer>(); for(int i = 1;i <
		 * N;i++) { remain.add(i); } while(!PQ.isEmpty()) { int now = PQ.poll(); for(int
		 * i:remain) { if(MAP[now][i]) { ans[i] = now; PQ.add(i); }else {
		 * remain_buf.add(i); } } if(remain_buf.isEmpty())break; remain = new
		 * ArrayList<Integer>(); remain.addAll(remain_buf); remain_buf = new
		 * ArrayList<Integer>(); }
		 *
		 * System.out.println("Yes"); for(int i = 1;i < N;i++) {
		 * System.out.println(ans[i]+1); }
		 */

		ArrayList<ArrayList<Integer>> map = new ArrayList<ArrayList<Integer>>();
		for (int i = 0; i < N; i++) {
			map.add(new ArrayList<Integer>());
		}
		for (int i = 0; i < M; i++) {
			int A = scn.nextInt() - 1, B = scn.nextInt() - 1;
			map.get(A).add(B);
			map.get(B).add(A);
		}

		ArrayDeque<Integer> AD = new ArrayDeque<Integer>();
		AD.add(0);
		int ans[] = new int[N];

		while (!AD.isEmpty()) {
			int n = AD.poll();
			for (int i : map.get(n)) {
				if (ans[i] == 0) {
					ans[i] = n+1;
					AD.add(i);
				}
			}
		}
		System.out.println("Yes");
		for (int i = 1; i < N; i++) {
			System.out.println(ans[i]);
		}

	}

}


Measured memory_bytes: 77104
#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 MOD 1000000007

typedef long long int ll;

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

int main(){
  int N;
  cin >> N;
  string s,t;
  cin >> s >> t;
  REP(i,N)cout << s[i] << t[i];
  cout << endl;
}



Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
typedef long long ll ;
#define pll pair<ll , ll >
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
using namespace std;
const int maxn = 1000*1000+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;
ll n , a[maxn] ; 
pii p[maxn] ; 
int main()
{
	migmig ;
	cin>>n ; 
	for(int i = 1 ; i<= n ; i ++ )
	{
		for(int j = i ; j <= n ; j += i)
		{
			a[j] ++ ; 
		}
	}
	ll ans = 0 ; 
	for(int i = 1 ; i < n ; i ++ )
	{
		ans += a[i] ; 
	}
	cout<<ans ; 
}








Measured memory_bytes: 11464